我将尝试使用以下代码创建 JSON:
JArray jInner = new JArray("document");
JProperty jTitle = new JProperty("title", category);
JProperty jDescription = new JProperty("description", "this is the description");
JProperty jContent = new JProperty("content", content);
jInner.Add(jTitle);
jInner.Add(jDescription);
jInner.Add(jContent);
当我到达 jInner.Add(jTitle)
时,我会得到以下异常:
System.ArgumentException: Can not add Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JArray.
at Newtonsoft.Json.Linq.JContainer.ValidateToken(JToken o, JToken existing)
at Newtonsoft.Json.Linq.JContainer.InsertItem(Int32 index, JToken item, Boolean skipParentCheck)
at Newtonsoft.Json.Linq.JContainer.AddInternal(Int32 index, Object content, Boolean skipParentCheck)
有人可以帮忙告诉我我在做什么错了吗?