Accessing JSON data

后端 未结 4 495
轮回少年
轮回少年 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

    alert( data.d[1].col1 ) ;
    

    In human:

    1. start at data variable
    2. go to d property.
    3. d is an array, so look up the value at index 1 (second value)
    4. look up the col1 property of that value.

    May I suggest console.log? In Chrome and with Firefox/Firebug it will give you a nice log message which tells you more about your data.

提交回复
热议问题