首页 > 代码库 > 字符串json转换为xml xml转换json

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

原文:字符串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);

  

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