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; }
        }
    }
  • 相关阅读:
    Windows环境安装tesseract-ocr 4.00并配置环境变量
    python问题集
    使用CefSharp在.Net程序中嵌入Chrome浏览器(八)——Cookie
    python虛擬環境和工具
    pycharm使用(持续更新)
    醒过来的都市
    下一个十年计划6-作品
    下一个十年计划5-方向选择
    下一个十年计划4-反向选择
    负逻辑的实际应用
  • 原文地址:https://www.cnblogs.com/zcm123/p/6144162.html
Copyright © 2011-2022 走看看