How to convert JSON to XML or XML to JSON in C# ?

Published on February 15, 2017 by admin

Filed under C#

Last modified February 15, 2017

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 15693 times

Below is a sample code snippet demonstrating how you can convert the Json to XML and vice versa in C# using Json.NET.

How to convert JSON to XML or XML to JSON in C# ?

var xmlData = "<xmlcontent></xmlcontent>" 
XmlDocument doc = new XmlDocument();
string jsonText = JsonConvert.SerializeXmlNode(doc);

// Convert Json back to XML
XmlDocument xmlDoc = JsonConvert.DeserializeXmlNode(json);

Leave a Comment


You might be Interested in these Posts

Json.NET & VB.NET – How to Serialize an Collection?

Do you want to serialize an collection in your VB.NET application?. Json.NET supports this functiona...

How to Convert a string in JSON.NET to XML in C# ?

You can use the JsonConvert.DeserializeXmlNode method of JSON.NET to convert from the json string to...

How to Convert XmlDocument to XDocument in C# ?

If you want to convert an XmlDocument to XDocument in C# , you can use the XmlNodeReader which does ...