Json.NET - Converting JSON to XML and Vice Versa

Json.Net supports the conversion from XML to JSON and JSON and XML vice versa.

JSON to XML Conversion.

We are going to use 

DeserializeXNode(string json, string nodeName)

method defined in JsonConvert class to convert JSON to XML It will return an XNode object containing the XML. You will need to import System.Xml and System.Xml.Linq namespaces for this sample to work correctly

XML to JSON Conversion

We are going to use the following method

SerializeXmlNode(XmlDocument document)

method for doing the conversion from XML to JSON. This method will return a string containing the json. First you need to load the xml into an instance of XmlDocument and then call the SerializeXmlNode method defined in JsonConvert class to do the conversion.


No Comments

Add a Comment