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 XML format and viceversa?
相关问题
- Jackson Deserialization not calling deserialize on
- Sorting 3 numbers without branching [closed]
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- Graphics.DrawImage() - Throws out of memory except
I searched for a long time to find alternative code to the accepted solution in the hopes of not using an external assembly/project. I came up with the following thanks to the source code of the DynamicJson project:
Note: I wanted an XmlDocument rather than an XElement for xPath purposes. Also, this code obviously only goes from JSON to XML, there are various ways to do the opposite.
Yes. Using the JsonConvert class which contains helper methods for this precise purpose:
Documentation here: Converting between JSON and XML with Json.NET
Here is a simple snippet that converts a XmlNode (recursively) into a hashtable, and groups multiple instances of the same child into an array (as an ArrayList). The Hashtable is usually accepted to convert into JSON by most of the JSON libraries.
Cinchoo ETL - an open source library available to do the conversion of Xml to JSON easily with few lines of code
Xml -> JSON:
JSON -> Xml:
Checkout CodeProject article for some additional help.
Disclaimer: I'm the author of this library.
I have used the below methods to convert the JSON to XML
and
I have used the class named Item to represent the elements
It works....
You can do these conversions also with the .NET Framework:
JSON to XML: by using System.Runtime.Serialization.Json
XML to JSON: by using System.Web.Script.Serialization