Blogger Information
Blog 91
fans 0
comment 0
visits 203201
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JSON定义一维和二维数组格式
何澤小生的博客
Original
6085 people have browsed it

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

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post