<script>//var json3={name:"longzhoufeng",age:123}//第一种方式var json3={"name":"longzhoufeng","age":123}//推荐这种方式,加引号,安全性高一点,转换格式好一些for( var attr in json3){ //alert(attr)//name,age console.log(json3[attr])//longzhoufeng,123}</script>
<script>//对象里包数组var json4={ "url":["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg"], "text":["aaaa","bbbb","cccc","dddd"]}for(var att in json4){ console.log(json4[att]) for(var i=0;i<json4[att].length;i++){ console.log(json4[att][i]) }}</script>
运行结果:
数组里包对象
<script>var json5=[{"姓名":"longzhoufeng","年龄":123},{"姓名":"minigui","年龄":25}]for(var i=0;i<json5.length;i++){ for(var att in json5[i]){ //alert(att) console.log(json5[i][att]) }}</script>