Skip to content

Instantly share code, notes, and snippets.

@deepumi
Created September 26, 2016 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepumi/0ce1fd6e018d170c6b64b2c313cbe242 to your computer and use it in GitHub Desktop.
Save deepumi/0ce1fd6e018d170c6b64b2c313cbe242 to your computer and use it in GitHub Desktop.
Convert json string to XML node from reflection
using System.Runtime.Serialization.Json;
using System.Text;
using System.Xml.Linq;
internal static string JsonToXmlResponse(this Type type)
{
if (type == null) return string.Empty;
var json = new ObjectGenerator().GenerateObject(type).Serialize();
var xml = XDocument.Load(JsonReaderWriterFactory.CreateJsonReader(Encoding.ASCII.GetBytes(json), new XmlDictionaryReaderQuotas()));
return xml.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment