代码改变世界

c# xml、json相互转换

  bgbing  阅读(885)  评论(0编辑  收藏  举报
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string jsonString = "{\"Table\":{\"Row\":[{\"Name\":\"张三\",\"Age\":\"20\"},{\"Name\":\"李四\",\"Age\":\"25\"}]}}";
//json to xml
XmlDocument xd1 = new XmlDocument();
xd1 = JsonConvert.DeserializeXmlNode(jsonString);
string xmlstring = xd1.InnerXml;
DebugHelper.WriteDebugLog(xd1.InnerXml);
DebugHelper.WriteDebugLog(xd1.OuterXml);
//xml to json
XmlDocument xd2 = new XmlDocument();
xd2.LoadXml(xmlstring);
string jsonstrin2 = JsonConvert.SerializeXmlNode(xd1);
 
DebugHelper.WriteDebugLog(string.Format("intputjson:{0}", jsonString));
DebugHelper.WriteDebugLog(string.Format("jsontoxml:{0}",jsonstrin2));

  

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
点击右上角即可分享
微信分享提示