html,body{width:100%;height:100%;margin:0;}
//参考链接:http://www.jsons.cn/articleinfo/8/
var json = {
"alexa": {
"@attributes": {
"ver": "0.9",
"url": "http://coursesweb.net/",
"home": "0",
"aid": "="
},
"#text": "",
"sd": [
{
"@attributes": {
"title": "a",
"host": "coursesweb.net"
},
"#text": "",
"title": {
"#text": "CoursesWeb: php, mysql, html, css, javascript, ajax, jquery, actionscript, flash"
},
"linksin": {
"@attributes": {
"num": "1102"
}
},
"speed": {
"@attributes": {
"pct": "51"
},
"#text": "4578"
}
},
{
"#text": "",
"popularity": {
"#text": "5777"
},
"reach": {
"@attributes": {
"rank": "5952"
}
},
"rank": {
"@attributes": {
"url": "http://coursesweb.net/"
},
"#text": "6667"
}
}
]
}
};
var xml_content = $.json2xml(json);
console.log(xml_content);
var xmlstr = `
CoursesWeb: php, mysql, html, css, javascript, ajax, jquery, actionscript, flash4578
5777
6667
`;
var json_obj = $.xml2json(xmlstr);
console.log(json_obj);
这篇博客展示了如何使用JavaScript库将XML数据转换为JSON对象,以及将JSON对象转换回XML字符串。通过示例代码,作者演示了$.json2xml()和$.xml2json()这两个函数的用法,这些函数在处理数据交换和解析时非常实用。
1559

被折叠的 条评论
为什么被折叠?



