当前位置: 首页 > news >正文

Newtonsoft.Json use


        private void button3_Click(object sender, EventArgs e)
        {
            List<Student> students = new List<Student>();

            students.Add(new Student { Id = 1, Name = "张三", Sex = "男", Description = "班长" });

            students.Add(new Student { Id = 2, Name = "李四", Sex = "女", Description = "小组长" });

            students.Add(new Student { Id = 3, Name = "王五", Sex = "男", Description = "宣传委员" });


            string studentsJson = JsonConvert.SerializeObject(students);
            MessageBox.Show(studentsJson);
            Console.WriteLine(studentsJson);


            //
            Dictionary<String, Object> dicList = new Dictionary<string, object>();
            Dictionary<String, string> dicSampleList = new Dictionary<string, string>();
            dicSampleList.Add("key_1", "111");
            dicSampleList.Add("key_2", "222");
            dicList.Add("SampleDatas", dicSampleList);
            List<Dictionary<string, object>> tableItems = new List<Dictionary<string, object>>();
            var properties = typeof(Student).GetProperties();

            foreach (var stu in students)
            {
                Dictionary<string, object> row = new Dictionary<string, object>();
                foreach (System.Reflection.PropertyInfo info in properties)
                {
                    var value = stu.GetType().GetProperty(info.Name).GetValue(stu, null);
                    //Console.WriteLine(info.Name,value);
                    row.Add(info.Name,value);
                    
                }
                tableItems.Add(row);
            }
            
            dicList.Add("Table1", tableItems);
            string customJson = JsonConvert.SerializeObject(dicList);
            MessageBox.Show(customJson);
            Console.WriteLine(customJson);

            var desobj = JsonConvert.DeserializeObject<Dictionary<string, object>>(customJson);
            var dicSample =JsonConvert.DeserializeObject<Dictionary<string, object>>(desobj["SampleDatas"].ToString());
            var dicTable1 = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(desobj["Table1"].ToString());

            Console.WriteLine(desobj.ToString());
            MessageBox.Show(desobj.ToString());
        }
      

http://www.lryc.cn/news/188342.html

相关文章:

  • MySQL-3(9000字详解)
  • SLAM从入门到精通(3d 点云数据访问)
  • 如何在 Spring Boot 中提高应用程序的安全性
  • 【Vuex+ElementUI】
  • 多媒体播放软件 Infuse mac中文特点介绍
  • 华为数通方向HCIP-DataCom H12-831题库(单选题:201-220)
  • 【管理运筹学】第 9 章 | 网络计划(2,时间参数的计算 —— 工作时间的确定与事项的时间参数)
  • 英语——方法篇——单词——羊肉串记忆法——单词密码
  • 【m98】视频帧的 jitterbuffer 1:
  • javascript中map和filter的区别与联系
  • 【RabbitMQ 实战】10 消息持久化和存储原理
  • vscode 连接ubuntu git下载缓慢
  • 2731. 移动机器人
  • 小程序实现人脸识别功能
  • 【】javax.crypto.IllegalBlockSizeException: Input length not multiple of 8 bytes
  • 312.戳气球
  • get_trade_detail_data函数使用
  • 【融合ChatGPT等AI模型】Python-GEE遥感云大数据分析、管理与可视化及多领域案例实践应用
  • LeetCode862 和至少为k的最短子数组
  • 网卡bonding模式 - bond模式配置介绍
  • 做了个 chrome 插件实现 B 站视频截图功能,直接从当前视频帧无损复制
  • Docker linux 安装
  • windows部署django服务器
  • ChatGPT prompt汇总-个人使用-持续更新....
  • Vue实现简单的接口封装
  • 软件测试工具有什么作用?有哪些好用的测试工具推荐?
  • 写爬虫?前端er何必用python
  • 交通物流模型 | 基于交通图卷积长短时记忆网络的网络级交通流预测
  • web 基础和http 协议
  • Java常量与变量