版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Document</title> <script> function Analy_json1(){ var Strs1 =[{"name":"daobin","course":"网站前端技术","dept":"软件系"}, {"name":"张三","course":"linux","dept":"软件系"}, {"name":"李四","course":"j2ee","dept":"软件系"}]; var _Json1 = eval(Strs1); for(var i=0; i <= _Json1.length - 1 ; i++){ document.getElementById("result1").innerHTML += "姓名:" + _Json1[i].name + ",dept:" + _Json1[i].dept +",course:"+_Json1[i].course+ "<br />"; } } //定义复杂的json数据 function Analy_json2() { var Strs2 = {"name": "中国","province": [{"name": "云南省","caties": {"city": ["昆明市", "红河州"] }}, {"name": "广东省","caties": {"city": ["广州市", "深圳市", "珠海市"]} }]} var _Json2 = eval(Strs2); for (i = 0; i <= _Json2.province.length - 1; i++) { document.getElementById("result2").innerHTML += _Json2.name + "<span>\n</span>" + _Json2.province[i].name + "<span>\n</span>" + _Json2.province[i].caties.city + "<br />"; } } </script> </head> <body> <input type="button" value="简单JSON解析" onclick="Analy_json1()" /> <span style="white-space:pre"> </span><div id="result1"></div> <span style="white-space:pre"> </span><input type="button" value="复杂JSON解析" onClick="Analy_json2()"> <span style="white-space:pre"> </span><div id="result2"></div> </body> </html>
原文链接:https://www.idaobin.com/archives/231.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告