我正在尝试使用 jQuery 来解析来自 Youtube API 的一些 JSON,这是我到目前为止的代码:
// these are defined in my real code
var ajaxURL = URL + UserName + jsonFormat;
var myObject = JSON.stringify(ajaxURL);
$.getJSON(ajaxURL, function(data){
var htmlString = "";
$.each(data.data.items, function(i,item){
// Here's where we piece together the HTML
htmlString += '<img src="';
htmlString += item.thumbnail;
htmlString += '">';
});
// Pop our HTML in the #image DIV
$('#image').html(htmlString);
});
JSON看起来像(这已被削减):
"data": {
"updated": "2013-09-09T18:48:57.730Z",
"totalItems": 1,
"startIndex": 1,
"itemsPerPage": 1,
"items": [{
"id": "theID",
"uploaded": "2013-09-05T13:48:53.000Z",
"updated": "2013-09-05T13:49:23.000Z",
"uploader": "username",
"category": "People",
"title": "the title",
"description": "the description",
"thumbnail": {
"sqDefault": "https://i1.ytimg.com/vi/erferfr/default.jpg",
"hqDefault": "https://i1.ytimg.com/vi/erferfr/hqdefault.jpg"
},
我已经尝试过.item.thumbnail[0]
,但这仍然不起作用。
非常感谢任何帮助 - 对 JSON 来说相当新!