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:28

    I thought it's worth linking to the Documentation for turning xml to json and the other way around.

    The guys are right..

    // To convert an XML node contained in string xml into a JSON string   
    XmlDocument doc = new XmlDocument();
    doc.LoadXml(xml);
    string jsonText = JsonConvert.SerializeXmlNode(doc);
    
    // To convert JSON text contained in string json into an XML node
    XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);
    

提交回复
热议问题