zoukankan      html  css  js  c++  java
  • Newtonsoft.Json之JArray, JObject, JProperty,JValue

    JObject staff = new JObject();

                staff.Add(new JProperty("Name", "Jack"));

                staff.Add(new JProperty("Age", 33));

                staff.Add(new JProperty("Department", "Personnel Department"));

                staff.Add(new JProperty("Leader", new JObject(new JProperty("Name", "Tom"), new JProperty("Age", 44), new JProperty("Department", "Personnel Department"))));

                Console.WriteLine(staff.ToString());

     

      

                JArray arr = new JArray();

                arr.Add(new JValue(1));

                arr.Add(new JValue(2));

                arr.Add(new JValue(3));

                Console.WriteLine(arr.ToString());

     

    string json = "{"Name" : "Jack", "Age" : 34, "Colleagues" : [{"Name" : "Tom" , "Age":44},{"Name" : "Abel","Age":29}] }";

    获取该员工的姓名

                //将json转换为JObject

                JObject jObj = JObject.Parse(json);

                //通过属性名或者索引来访问,仅仅是自己的属性名,而不是所有的

                JToken ageToken =  jObj["Age"];

                Console.WriteLine(ageToken.ToString());

     

    萌橙 你瞅啥?
  • 相关阅读:
    GO学习-(31) Go语言操作Elasticsearch
    GO学习-(30) Go语言操作kafka
    GO学习-(29) Go语言操作etcd
    Maven+Spring打Jar包
    话说Session
    Apache Server与多个独立Tomcat集成
    一套Tomcat处理多个域名请求
    Tomcat多实例
    Linux下安装MySQL
    Java Enum
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/11669877.html
Copyright © 2011-2022 走看看