Lasitha Yapa Lasitha Yapa - 1 year ago 132
C# Question

Convert a json text with attributes to xml

I have the following json, which is converted from a XML.


When i use
function to convert this back to XML it gives me following exception.

System.InvalidCastException: Unable to cast object of type 'Newtonsoft.Json.Converters.XmlDocumentWrapper' to type 'Newtonsoft.Json.Converters.IXmlElement'.

How can I do this?

Answer Source
var result = JsonConvert.DeserializeXNode(json, "Root");

<Root number="0">
 <Field key="status">

This is working without a problem. Be aware that @number and @key will be attributes of specific nodes!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download