0

I am trying to find a way to serialize an object to json using json.net. The object i am trying to serialize has a XElement property, and i would like to keep it as is so.

is there a way to do that in json.net ? or what the mechanism to transfer xml data in json object?

1
  • To transport XML as JSON: 1) Convert it to JSON (but not done with an automatic converter and using some "possibly lossy" rules), or 2) Shove the XML in a string. In the case of #2 Json.NET will not touch the contents. Case #1 might be automatically possible by registering the appropriate converters. Commented Jan 25, 2013 at 22:10

1 Answer 1

1

you can do that like this

 //convert XML node contained in string xml into a JSON string   
 XmlDocument var = new XmlDocument();
 var.LoadXml(xml);
 string jsonsting = JsonConvert.SerializeXmlNode(var);

see this link for more help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.