zoukankan      html  css  js  c++  java
  • C#解析Json(多方法解析Json 一)

     解析:{'id':'4028d80858053bed0158053ef7a50001','sl':0.0,'sfyfz':'0','zwjyzsbh':'1000001600000018'}

     1、新建winform控制台项目

    2、在项目里新建一个实体类test.cs

    class test
        {
           
            public string id { get; set; }
            public string sl { get; set; }
            public string sfyfz { get; set; }
            public string zwjyzsbh { get; set; }
      
        }

     3、在Program.cs的Main方法里(方法一):  引用Newtonsoft.Json,反序列化

    class Program
        {
            static void Main(string[] args)
            {
               
                string json=@"[{'id':'22222222','sl':0.0,'sfyfz':'0','zwjyzsbh':'333333333'}]";
                
                List<test> jobInfoList = JsonConvert.DeserializeObject<List<test>>(json);
                foreach (test jobInfo in jobInfoList)
                {
                  
                    Console.WriteLine("id:" + jobInfo.id);
                }
                Console.ReadLine();
            }
        }

    string json这个字符串,里面都是单引号才可以,或者把单引号变为("),即斜杠+双引号,

    string json=@"[{"id":"22222222","sl":0.0,"sfyfz":"0","zwjyzsbh":"333333333"}]";

    要引用Newtonsoft.Json(nuget下载)

    3、在Program.cs的Main方法里(方法二)  :JsonReader 

    class Program
        {
            static void Main(string[] args)
            {
               
                string json = @"[{'id':'4028d80858053bed0158053ef7a50001','sl':0.0,'sfyfz':'0','zwjyzsbh':'1000001600000018'}]";
                JsonReader reader = new JsonTextReader(new StringReader(json));
    
                while (reader.Read())
                {
                    Console.WriteLine(reader.Value);
                }
                Console.ReadLine();
            }
        }
  • 相关阅读:
    [转]ExtJS之遍历Store
    [转]Ext ComboBox 默认选中某一项
    [转]extjs render 用法介绍
    [转]Extjs combo数据绑定与获取
    [转]ExtJs:xtype的含义
    java 使用POI批量导入excel数据
    面临读研,找工作杂感
    二维“有序”数组查找问题的解决
    操作系统——进程调度之短进程优先
    阶乘相关问题
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/6016767.html
Copyright © 2011-2022 走看看