JSON 教程
JSON 数组
我们可以使用 for-in 来循环访问每个数组
源代码:
点击运行 »
<p>循环内嵌数组:</p> <p id="demo"></p> <script> var myObj, i, j, x = ""; myObj = { "name": "网站", "num": 3, "sites": [{ "name": "Google", "info": ["Android", "Google 搜索", "Google 翻译"] }, { "name": "Mifengjc", "info": ["蜜蜂教程", "菜鸟工具", "菜鸟微信"] }, { "name": "Taobao", "info": ["淘宝", "网购"] } ] } for (i in myObj.sites) { x += "<h1>" + myObj.sites[i].name + "</h1>"; for (j in myObj.sites[i].info) { x += myObj.sites[i].info[j] + "<br>"; } } document.getElementById("demo").innerHTML = x; </script>
运行结果:
点击运行 »