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;
}
}
}
本文来源:https://www.wddqw.com/doc/b9bf5935c77da26924c5b007.html
正在阅读:
C#中XML和json互相转换01-01
家庭称呼英语单词01-01
祖国在我心中800字作文01-01
AU3代码(QQ6.3)01-01
真心朋友的句子经典高冷霸气网名01-01
成长中的温暖作文600字_作文01-01
新人教版三年级数学上册第二单元测试题01-01
综合体能训练方法01-01
记忆中的味道_高中作文01-01