Newtonsoft.Json.Linq

JArray

JArray是数组对象,可以作为json中子项键的值,不能作为一个完整的条目。

JObject rss = new JObject();
JProperty jPropertyID = new JProperty("ID", "1");
JArray jArray = new JArray();
jArray.Add("Green");
jArray.Add("Read");
JProperty jPropertyColors = new JProperty("Colors", jArray);
rss.Add(jPropertyID);
rss.Add(jPropertyColors);
JObject childValue = new JObject();
childValue.Add(jPropertyColors);
JProperty jPropertyChild = new JProperty("child");
jPropertyChild.Value = childValue;
rss.Add(jPropertyChild);
string str = rss.ToString();
Console.WriteLine(str);


{
"ID": "1",
"Colors": [
    "Green",
    "Read"
],
"child": {
    "Colors": [
    "Green",
    "Read"
    ]
}
}