我正在尝试使用以下代码创建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);
Run Code Online (Sandbox Code Playgroud)
当我到达时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)
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮忙告诉我,我做错了什么?