[代码]XML TO JSON
01 |
string xml = @"<?xml version=""1.0"" standalone=""no""?> |
04
<name>Alan</name> |
05 |
<url>http://www.google.com</url> |
06
</person> |
08
<name>Louis</name> |
09 |
<url>http://www.yahoo.com</url> |
10
11 |
</root>"; |
12
|
13 |
XmlDocument doc = new XmlDocument(); |
14
doc.LoadXml(xml); |
16
jsonText = JsonConvert.SerializeXmlNode(doc); |
18
// "?xml": { |
20
// "@standalone": "no" |
21 |
// },monospace!important; font-size:10pt!important; min-height:inherit!important; display:block!important">22 |
// "root": { |
24
// { |
25 |
// "@id": "1",monospace!important; font-size:10pt!important; min-height:inherit!important; display:block!important">26 |
// "name": "Alan", |
27 |
// "url": "http://www.google.com" |
28
29 |
// { |
30
// "@id": "2",monospace!important; font-size:10pt!important; min-height:inherit!important; display:block!important">31 |
// "name": "Louis",monospace!important; font-size:10pt!important; min-height:inherit!important; display:block!important">32 |
// "url": "http://www.yahoo.com" |
34
// ] |
@H_549_
403@
[代码]JSON TO XML
json =@"{
""?xml"": {
""@version"": ""1.0"",monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""@standalone"": ""no"" |
},monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""root"": { |
{
""@id"": ""1"",monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""name"": ""Alan"",monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""url"": ""http://www.google.com"" |
{
""@id"": ""2"",monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""name"": ""Louis"",monospace!important; font-size:10pt!important; min-height:inherit!important; color:blue!important">""url"": ""http://www.yahoo.com""
]
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json); |
// <?xml version="1.0" standalone="no"?> |
// <root>
// <name>Alan</name>
// <url>http://www.google.com</url> |
// </person>
// <name>Louis</name>
// <url>http://www.yahoo.com</url> |
// </root>