【发布时间】:2013-09-13 08:28:38
【问题描述】:
我正在尝试使用 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 来说相当新!
【问题讨论】:
-
你试过
item.thumbnail.sqDefault吗? -
试试
item.thumbnail["sqDefault"] -
@SB - 完美 - 请将此作为答案,以便我接受。以为我是对的!
标签: jquery json youtube-api