JSON定义一维和二维数组格式


 

JSON定义一维数组:

示例完整代码:

<script>
var UserList = [{
"UserID": 11,
"Name": {
"FirstName": "Truly",
"LastName": "Zhu"
},
"Email": "zhuleipro◎hotmail.com"
},
{
"UserID": 12,
"Name": {
"FirstName": "Scott",
"LastName": "Gu"
},
"Email": "xxx2◎xxx2.com"
}];
alert(UserList[0].Name.FirstName);
</script>

事实上除了使用"."引用属性外,我们还可以使用下面语句:

alert(UserList[0]["Name"]["FirstName"]); 或者 alert(UserList[0].Name["FirstName"]); 
 
JSON定义二维数组:

示例完整代码:

 

var UserList = {
"rec": [{
"recs": [{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
},
{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
}]
},
{
"recs": [{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
},
{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
}]
}],
"rec": [{
"recs": [{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
},
{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
}]
},
{
"recs": [{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
},
{
"temLink": "132",
"imageLink": "",
"itemPrice": "",
"itemLink": "",
"itemName": ""
}]
}]

};
alert(UserList.rec[0].recs[0].temLink);


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com