简单的jQuery解析json数据
<span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">尊重劳动成果,转载请注明出处(http://blog.csdn.net/sllailcp/article/details/41113275)...</span>
以下是摘取部分json,jQuery需自己引入;
<!doctype html>
<html> <head> <meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript"> $(function(){ var province_enum = [ {id: 1, name: '北京', city: [ {id: 1, name: '北京市', district: [ {id: 1, name: '东城区'}, {id: 2, name: '西城区'}, {id: 3, name: '崇文区'}, {id: 4, name: '宣武区'}, {id: 5, name: '朝阳区'}, {id: 6, name: '丰台区'}, {id: 7, name: '石景山区'}, {id: 8, name: '海淀区'}, {id: 9, name: '门头沟区'}, {id: 10, name: '房山区'}, {id: 11, name: '通州区'}, {id: 12, name: '顺义区'}, {id: 13, name: '昌平区'}, {id: 14, name: '大兴区'}, {id: 15, name: '怀柔区'}, {id: 16, name: '平谷区'}, {id: 17, name: '密云县'}, {id: 18, name: '延庆县'} ]} ]}, {id: 2, name: '天津', city: [ {id: 2, name: '天津市', district: [ {id: 19, name: '和平区'}, {id: 20, name: '河东区'}, {id: 21, name: '河西区'}, {id: 22, name: '南开区'}, {id: 23, name: '河北区'}, {id: 24, name: '红桥区'}, {id: 25, name: '塘沽区'}, {id: 26, name: '汉沽区'}, {id: 27, name: '大港区'}, {id: 28, name: '东丽区'}, {id: 29, name: '西青区'}, {id: 30, name: '津南区'}, {id: 31, name: '北辰区'}, {id: 32, name: '武清区'}, {id: 33, name: '宝坻区'}, {id: 34, name: '宁河县'}, {id: 35, name: '静海县'}, {id: 36, name: '蓟县'} ]} ]}, ] for(var x=0;x<province_enum.length;x++){ document.write('省:'+'id:'+province_enum[x].id+','+'name:'+province_enum[x].name+'<br>') for(var y=0;y<province_enum[x].city.length;y++){ document.write('市:'+'id:'+province_enum[x].city[y].id+','+'name:'+province_enum[x].city[y].name+'<br>') for(var z=0;z<province_enum[x].city[y].district.length;z++){ document.write('区:'+'id:'+province_enum[x].city[y].district[z].id+','+'name:'+province_enum[x].city[y].district[z].name+'<br>') } } } }); </script> </head> <body> <pre name="code" class="html"><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);"><a href="</span><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">http://blog.csdn.net/sllailcp/article/details/41113275</span><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">"></span><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">(</span><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">尊重劳动成果,转载请注明出处</span><span style="color: rgb(51, 51, 51); font-size: 14px; line-height: 26px; font-family: Arial; background-color: rgb(255, 255, 255);">)...</span><span style="color: rgb(51, 51, 51); font-family: Arial; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);"></a></span></body></html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。