我正在尝试使用 JSON.NET 从 xml 创建 JSON
XmlDocument docPerson = new XmlDocument();
docPerson.LoadXml(xmlPerson); //xmlPerson is the xml from above
JObject personDefinition = JObject.Parse(JsonConvert.SerializeObject(docPerson));
Tasks.personDefinition = personDefinition["personDefinition"];
输出 JSON
"person":{"person":[{"personId":"1","firstName":"Name1","lastName":"lastName1"}, {"personId":"3","firstName":"Name2","lastName":"lastName2"}]}
我不需要外人,只需要下面的json
必需的 JSON
"person":[{"personId":"1","firstName":"1","lastName":"Weight"},{"personId":"3","firstName":"4","lastName":"Pulse Ox"}]}
我曾尝试使用 .first 方法,但它会引发错误。任何人都可以建议如何从输出 json 中删除根