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; }
        }
    }
  • 相关阅读:
    LeetCode15题: 寻找三数和,附完整代码
    LeetCode 11 水池蓄水问题
    分布式初探——分布式事务与两阶段提交协议
    高等数学——讲透求极限两大方法,夹逼法与换元法
    书籍推荐——一本老书,吴军老师《数学之美》
    概率统计——期望、方差与最小二乘法
    算法浅谈——递归算法与海盗分金问题
    机器学习基础——带你实战朴素贝叶斯模型文本分类
    线性代数精华——从正交向量到正交矩阵
    LeetCode10 Hard,带你实现字符串的正则匹配
  • 原文地址:https://www.cnblogs.com/zcm123/p/6144162.html
Copyright © 2011-2022 走看看