zoukankan      html  css  js  c++  java
  • C#中XML和json互相转换

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Xml;
    using Newtonsoft;//此方法需单独下载
    
    namespace ThumbsLotteryTicket.MyMethond
    {
        public class XML_JSON
        {
            /// <summary>
            /// 返回指定节点下信息的JSON格式字符串
            /// </summary>
            /// <param name="str">xml字符串</param>
            /// <param name="nodename">节点名称,应从根节点开始</param>
            /// <returns></returns>
            public string XML2Json(string str,string nodename)
            {
                string result = null;
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(str);
                XmlNode node = xmldoc.SelectSingleNode(nodename);
                result = Newtonsoft.Json.JsonConvert.SerializeXmlNode(node);
                return result;
            }
    
            public string Json2XML(string str)
            {
                string result = null;
                XmlDocument xml = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(str);
                result = xml.OuterXml;
                return result;
            }
        }
  • 相关阅读:
    experiment 2
    experiment 5
    php 代码审计之变量覆盖
    experiment 4
    experiment 3
    experiment 1
    2018铁三测评WP
    Lesson 1
    实验四、决策树算法及应用
    实验三 朴素贝叶斯算法及应用
  • 原文地址:https://www.cnblogs.com/JuneZhang/p/5146413.html
Copyright © 2011-2022 走看看