If I am given the following data by a web-service:
{
"d": [
{
"col1": "col 1 data 1",
"col2": "col 2 data 1"
},
{
"col1": "col 1 data 2",
"col2": "col 1 data 2"
}
]
}
how do I access the second col1?
As the following:
success: function( data ) {
alert( data.d ) ;
},
gives me:
[object Object],[object Object]
Its an array with 2 elements containing
col1
andcol2
, so something like:(
0
is the first element, and then you choose "col1")Try this:
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.In human:
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.