当前位置:首页 > 通信资讯 > 正文

c# json对象(C# JSON)

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

XML TO JSON

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 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" // }, // "root": { // "person": [ // { // "@id": "1", // "name": "Alan", // "url": "http://www.google.com" // }, // { // "@id": "2", // "name": "Louis", // "url": "http://www.yahoo.com" // } // ] // } //}

JSON TO XML

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 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); }
如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。