因此,在 C# 中,我创建了以下 Json:
{
"timeline": {
"headline": "Development timeline",
"type": "default",
"text": "timeline",
"startDate": "12/12/2011",
"date": [
{
"startDate": "2012,02,15",
"endDate": "2012,04,19",
"headline": "Development",
"text": "Coding"
},
{
"startDate": "2012,04,19",
"endDate": "2012,07,25",
"headline": "Development",
"text": "Coding"
},
{
"startDate": "2012,07,25",
"endDate": "2012,10,26",
"headline": "Development",
"text": "Coding"
}
]
}
}
使用 JObject:
jjson = new JObject(
new JObject(
new JProperty("timeline",
new JObject(
new JProperty("headline", "Development"),
new JProperty("type", "default"),
new JProperty("text", "timeline"),
new JProperty("startDate", "12/12/2011"),
new JProperty("date",
new JArray(
from p in timelineList
orderby p.releaseDate
select new JObject(
new JProperty("startDate", p.startDate),
new JProperty("endDate", p.endDate),
new JProperty("headline", p.headline),
new JProperty("text", p.text))
))))));
现在我希望在 json 对象的 date[] 中添加另一个部分,带有 startdate/enddate 但是我似乎不能这样做:(
我试图创建另一个 JArray 只是为了测试并查看它是否会附加到我的 json 但没有运气,因为我收到以下错误:“引用未设置为对象的实例:
JArray dd = new JArray();
dd = (JArray) jjson["date"];
dd.Add("item 1,sdsds");
如何向我已经创建的 JSON 添加另一个属性?谢谢