字符串json转换为xml xml转换json

// To convert an XML node contained in string xml into a JSON string    
XmlDocument doc = new XmlDocument(); 
doc.LoadXml(xml); 
string jsonText = JsonConvert.SerializeXmlNode(doc); 
 
// To convert JSON text contained in string json into an XML node 
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json); 

  

XmlNote myXmlNode = JsonConvert.DeserializeXmlNode(myJsonString);
 // or .DeserilizeXmlNode(myJsonString, "root");
 // if myJsonString does not have a root
 string jsonString = JsonConvert.SerializeXmlNode(myXmlNode); 

  

            XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(xml), XmlDictionaryReaderQuotas.Max);
            XmlDocument xdoc = new XmlDocument();
            xdoc.Load(reader);

  

posted @ 2011-12-23 16:57  小锋神  阅读(20232)  评论(0编辑  收藏  举报