官方 JSON.NET 地址
http://james.newtonking.com/pages/json-net.aspx
XML TO JSON
string xml = @""; 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" // } // ] // } //} Alan http://www.google.com Louis http://www.yahoo.com
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);
//
//
//
// Alan
// http://www.google.com
//
//
// Louis
// http://www.yahoo.com
//
//
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);
}



