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
        }
    
  • 相关阅读:
    code review
    自我封闭
    怎么验证?
    DRUPAL点滴
    CRLF CSRF XSS
    各种element/format 在manage display 下的选项
    html list <==> unformatted list
    ctrl + d 在phpstorm 和 eclipse 中的不同含义
    常量和变量的区别
    JSON和php里的数据序列化
  • 原文地址:https://www.cnblogs.com/taadis/p/12125959.html
Copyright © 2011-2022 走看看