码迷,mamicode.com
首页 > Web开发 > 详细

JObject 操作; Linq to JSON ;将json转换为JObject

时间:2020-01-08 10:52:24      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:string   log   self   add   ref   ring   person   访问   name   

https://www.cnblogs.com/gygang/p/8954376.html

d.data.replace(/LON:/g, "lng:")

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()); jObj["Age"] = 35; Console.WriteLine(jObj.ToString()); JToken colleagues = jObj["Colleagues"]; colleagues[0]["Age"] = 45; jObj["Colleagues"] = colleagues;//修改后,再赋给对象 Console.WriteLine(jObj.ToString()); jObj.Remove("Colleagues");//跟的是属性名称 Console.WriteLine(jObj.ToString()); jObj["Age"].Parent.AddAfterSelf(new JProperty("Department", "Personnel Department")); JObject linda = new JObject(new JProperty("Name", "Linda"), new JProperty("Age", "23")); jObj["Colleagues"].Last.AddAfterSelf(linda); JToken name = jObj.SelectToken("Name"); var names = jObj.SelectToken("Colleagues").Select(p => p["Name"]).ToList(); foreach (var name in names) var tends = from c in jObj.First.First.First.First.Children()

  

JObject 操作; Linq to JSON ;将json转换为JObject

标签:string   log   self   add   ref   ring   person   访问   name   

原文地址:https://www.cnblogs.com/yyzyou/p/12165084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!