zoukankan      html  css  js  c++  java
  • 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; }
        }
    }
  • 相关阅读:
    链堆栈的实现
    关于HyperLink的NavigateUrl属性的链接地址参数设置
    //yield return用于无缝实现迭代模式。
    NUnit的使用
    非常不错的数据访问架构
    Dictionary应用
    针对数据分析没态度的几句牢骚
    微软算法面试题(4)
    程序员面试题精选100题(60)判断二叉树是不是平衡的
    C++设计模式单件
  • 原文地址:https://www.cnblogs.com/zcm123/p/6144162.html
Copyright © 2011-2022 走看看