2016-08-29 5 views
0

ich dieses JSON analysiert:JavaScript: Parsen 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" 
     } 
     }, 

Mein Code (json_string enthält die oben JSON):

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

Wie kann ich videoId Wert bekommen?

+3

Warum Sie, bevor es das Parsen tun stringify? Das ist nicht JSON, das ist JSONP. – tkausl

Antwort

0

Sie erreichen es mit:

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

Gerade Nest it :)