国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#中使用JSON.NET實現JSON、XML相互轉換

2020-01-24 01:22:44
字體:
來源:轉載
供稿:網友

官方 JSON.NET 地址
http://james.newtonking.com/pages/json-net.aspx

XML TO JSON

string xml = @"<?xml version=""1.0"" standalone=""no""?><root> <person id=""1""> <name>Alan</name> <url>http://www.google.com</url> </person> <person id=""2""> <name>Louis</name> <url>http://www.yahoo.com</url> </person></root>"; XmlDocument doc = new XmlDocument();doc.LoadXml(xml); string jsonText = JsonConvert.SerializeXmlNode(doc);//{// "?xml": {//  "@version": "1.0",//  "@standalone": "no"http:// },// "root": {//  "person": [//   {//    "@id": "1",//    "name": "Alan",//    "url": "http://www.google.com"http://   },//   {//    "@id": "2",//    "name": "Louis",//    "url": "http://www.yahoo.com"http://   }//  ]// }//}

JSON TO XML

string json = @"{ ""?xml"": {  ""@version"": ""1.0"",  ""@standalone"": ""no"" }, ""root"": {  ""person"": [   {    ""@id"": ""1"",    ""name"": ""Alan"",    ""url"": ""http://www.google.com""   },   {    ""@id"": ""2"",    ""name"": ""Louis"",    ""url"": ""http://www.yahoo.com""   }  ] }}"; XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json);// <?xml version="1.0" standalone="no"?>// <root>//  <person id="1">//  <name>Alan</name>//  <url>http://www.google.com</url>//  </person>//  <person id="2">//  <name>Louis</name>//  <url>http://www.yahoo.com</url>//  </person>// </root>

DEMO:JSON TO XML

string json_str = "{/"a/":/"a/",/"b/":/"b/"}";//json 的字符串需要按照這個格式 書寫,否則會報錯string json = @"{ ""?xml"": {  ""@version"": ""1.0"",  ""@standalone"": ""no"" }, ""root"":" + json_str + "}"; if (!string.IsNullOrEmpty(json)){  XmlDocument doc = JsonConvert.DeserializeXmlNode(json);   }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 杭锦旗| 张北县| 建湖县| 九江县| 大丰市| 蚌埠市| 盱眙县| 崇明县| 宁陵县| 会昌县| 社旗县| 乐清市| 庐江县| 林口县| 宜君县| 滕州市| 凤城市| 仁化县| 天镇县| 崇仁县| 麻城市| 石棉县| 阿拉善左旗| 伽师县| 高密市| 樟树市| 旌德县| 桦南县| 凤山市| 壶关县| 布尔津县| 永济市| 留坝县| 娄底市| 交城县| 白玉县| 黔东| 乌兰浩特市| 上林县| 汾西县| 抚松县|