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);
原文:https://blog.csdn.net/syc001/article/details/6338477