qt xml 转html,js实现xml转json和json转xml

这篇博客展示了如何使用JavaScript库将XML数据转换为JSON对象,以及将JSON对象转换回XML字符串。通过示例代码,作者演示了$.json2xml()和$.xml2json()这两个函数的用法,这些函数在处理数据交换和解析时非常实用。
摘要由CSDN通过智能技术生成
js实现xml转json和json转xml

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, flash

4578

5777

6667

`;

var json_obj = $.xml2json(xmlstr);

console.log(json_obj);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值