How to convert JSON to XML or XML to JSON?

后端 未结 13 1269
借酒劲吻你
借酒劲吻你 2020-11-22 05:43

I started to use Json.NET to convert a string in JSON format to object or viceversa. I am not sure in the Json.NET framework, is it possible to convert a string in JSON to X

13条回答
  •  無奈伤痛
    2020-11-22 06:18

    Cinchoo ETL - an open source library available to do the conversion of Xml to JSON easily with few lines of code

    Xml -> JSON:

    using (var p = new ChoXmlReader("sample.xml"))
    {
        using (var w = new ChoJSONWriter("sample.json"))
        {
            w.Write(p);
        }
    }
    

    JSON -> Xml:

    using (var p = new ChoJsonReader("sample.json"))
    {
        using (var w = new ChoXmlWriter("sample.xml"))
        {
            w.Write(p);
        }
    }
    

    Checkout CodeProject article for some additional help.

    Disclaimer: I'm the author of this library.

提交回复
热议问题