• 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
        }
    
  • 相关阅读:
    小白安装使用Redis
    Mysql的Sql语句优化
    maximo入门----用户使用提要
    时不时刷刷BOSS 看看技术需求
    2019.7.10整理
    docker使用入门
    docker之windows安装&centOS安装
    HashTable学习
    Hashmap学习
    红黑树学习
  • 原文地址:https://www.cnblogs.com/taadis/p/12125959.html
Copyright © 2020-2023  润新知