Converting JSON to XML

后端 未结 6 1112
孤街浪徒
孤街浪徒 2020-12-10 02:58

I trying to convert JSON output into XML. Unfortunately I get this error:

JSON root object has multiple properties. The root object must have a single

6条回答
  •  余生分开走
    2020-12-10 03:48

    Despite the fact your JSON provided in the question is not complete, you have multiple properties at the top level as indicated by the exception. You have to define the root for it to get valid XML:

    var doc = JsonConvert.DeserializeXmlNode(jsonOutput, "root");
    

    EDIT: In order to print out your XML with indentation you can use XDocument class from System.Xml.Linq namespace: XDocument.Parse(doc.InnerXml).

提交回复
热议问题