• json 多重嵌套反序列化和序列化


    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string jsonString = "[{"downList": [],"line": {"Id": -1,"Name": "admin","icCard": "1"},"upList": [{"endTime": "18:10","startTime": "06:40","sId": 385,"sType": "38"},{"endTime": "18:10","startTime": "06:40","sId": 1036,"sType": "38"}]},{"downList": [],"line": {"Id": -1,"Name": "admin","icCard": "1"},"upList": [{"endTime": "18:10","startTime": "06:40","sId": 385,"sType": "38"},{"endTime": "18:10","startTime": "06:40","sId": 1036,"sType": "38"}]}]";
                Data[] datas = JsonConvert.DeserializeObject<Data[]>(jsonString);
    
                foreach (Data data in datas)
                {
                    downList[] downList = data.downList;
                    line line = data.line;
                    upList[] upLists = data.upList;
    
                    //输出
                    Console.WriteLine(string.Join(",", line.Id, line.Name, line.icCard));
                    foreach (upList upList in upLists)
                    {
                        Console.WriteLine(string.Join(",", upList.endTime, upList.startTime, upList.sId, upList.sType));
                    }
                    Console.WriteLine("-----------------------------------------------");
                }
            }
        }
    
    
        public class Data
        {
            public downList[] downList { get; set; }
            public line line { get; set; }
            public upList[] upList { get; set; }
        }
    
        public class downList
        {
    
        }
    
        public class line
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string icCard { get; set; }
        }
    
        public class upList
        {
            public string endTime { get; set; }
    
            public string startTime { get; set; }
    
            public int sId { get; set; }
    
            public string sType { get; set; }
        }
    }
  • 相关阅读:
    打印对象的 “精心骗局”
    js继承(自备水,这非常干货)
    递归实现深拷贝( 只要学过js递归,看不懂找我包会 )
    PuTTY SSH 使用证书免密码登录
    git 使用
    php socket通信的简单实现
    基于PHP实现短信验证码接口的方法
    PHP实现页面静态化的简单方法分享
    Yii2使用数据库操作汇总(增删查改、事务)
    PHP 获取当前页面的URL信息
  • 原文地址:https://www.cnblogs.com/zcm123/p/6144162.html
Copyright © 2020-2023  润新知