Mike Mike - 3 months ago 9
JSON Question

JavaScript: parsing JSON

I parsed this JSON:

foobar({
"kind": "youtube#searchListResponse",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/pHRM7wJ9wmWClTcY53S4FP4-Iho\"",
"nextPageToken": "CAUQAA",
"regionCode": "PL",
"pageInfo": {
"totalResults": 686,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/hpaieEHTq-SS7i8XR2SdBPqendk\"",
"id": {
"kind": "youtube#video",
"videoId": "j6r_N251pNQ"
}, "width": 480,
"height": 360
}
},
"channelTitle": "arhn.eu",
"liveBroadcastContent": "none"
}
},


My code (
json_string
contains the above JSON):

var json = JSON.parse(JSON.stringify(json_string));
alert(json['foobar']);


How can I get
videoId
value?

Answer

You can reach it with:

json['foobar']['items']['id']['videoId']

Just nest it :)

Comments