.net xml转json
首先添加引用------Newtonsoft.Json
using Newtonsoft.Json.Linq;//引用命名空间
string xml= "<?xml version=\"1.0\" encoding=\"utf-8\"?><body><head>test</head></body>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string json = Newtonsoft.Json.JsonConvert.SerializeXmlNode(doc);//xml转化json
json转xml:
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonText,"root");
xml转json:
XmlDocument doc = new XmlDocument();
doc.Load(xmlFileName);
string jsonText = JsonConvert.SerializeXmlNode(doc,Formatting.None,true);