JArray与JObject的使用方法

使用之前添加using Newtonsoft.Json.Linq;引用
JArray :
JArray arr = new JArray();
arr.Add(new JValue(1));
arr.Add(new JValue(2));
arr.Add(new JValue(3));
Console.WriteLine(arr.ToString());
JObject :
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());

posted @ 2020-12-01 13:14  S+1  阅读(406)  评论(0)    收藏  举报
Document