I am trying to convert some JSON to XML and then save it using JSON.NET in C# but i can’t seem to get it.
Here is what i have:
using System.XML;
using Newtonsoft;
XmlDocument doc = (XmlDocument)Newtonsoft.Json.JsonConvert.DeserializeXmlNode(json);
XmlTextWriter writer = new XmlTextWriter("json.xml", null);
writer.Formatting = Formatting.Indented;
doc.Save(writer);
I tested your code and it works totally fine for me. According to the documentation for
DeserializeXmlNodethis should definitely work:Test your method with the JSON string above, to verify if it works. I would say you are having a problem with your JSON not being valid.
You can validate your JSON for example here: