Accessing JSON data

后端 未结 4 530
轮回少年
轮回少年 2020-12-12 01:17

If I am given the following data by a web-service:

{
    \"d\": [
        {
            \"col1\": \"col 1 data 1\",
            \"col2\": \"col 2 data 1\"
           


        
4条回答
  •  星月不相逢
    2020-12-12 01:29

    Try this:

    var json = {
        "d": [
            {
                "col1": "col 1 data 1",
                "col2": "col 2 data 1"
            },
            {
                "col1": "col 1 data 2",
                "col2": "col 1 data 2"
            }
        ]
    };
    
    alert(json.d[1].col1);
    

    Specify the array index of d (starts with 0, so this would be 1) and then you can access child items. Here's a working example on jsFiddle.

提交回复
热议问题