zoukankan      html  css  js  c++  java
  • C#之json字符串转xml字符串

    留爪参考

    using System.Xml; //
    using System.Text; //
    using System.Runtime.Serialization.Json; //JsonReaderWriterFactory
    //以下method引用以上using
    
        /// <summary>
        /// Json字符串转xml字符串(utf-8)
        /// </summary>
        /// <param name="json">json字符串</param>
        /// <returns>xml字符串</returns>
        public string JsonToXml(string json)
        {
            string xml = string.Empty;
            XmlDocument xmlDoc = new XmlDocument();
            try
            {
                XmlDictionaryReader xmlReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(json), XmlDictionaryReaderQuotas.Max);
                xmlDoc.Load(xmlReader);
                //json转xml
    
                XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", "yes");
                //创建xml声明
                xmlDoc.InsertBefore(xmlDec, xmlDoc.DocumentElement); //插入xml声明
                //xmlDoc.AppendChild(xmlDec);
                //添加xml声明
            }
            catch (Exception ex)
            {          
                //
            }
            return xmlDoc.OuterXml; //xml转string
        }
    
  • 相关阅读:
    好多天没写了,郁闷
    昨天很受教育
    恼火的服务器
    欢迎访问我的博客网站
    体育产品论坛
    参考书目
    web2.0与数字标准
    用户产生内容与网站做内容
    Using x++ code reading data from csv file format
    Find out specified the folder for all the files
  • 原文地址:https://www.cnblogs.com/taadis/p/12125959.html
Copyright © 2011-2022 走看看