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