JavaScript返回[object,Object](JavaScript returning [object, Object])

编程入门 行业动态 更新时间:2024-10-26 15:14:09
JavaScript返回[object,Object](JavaScript returning [object, Object])

我正在尝试使用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来说还是新手!

I'm trying to use jQuery to parse some JSON from the Youtube API, here's my code so far:

// 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); });

The JSON looks like(this has been cut down):

"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" },

I have tried .item.thumbnail[0] but this still doesn't work.

Any help is much appreciated - rather new to JSON!

最满意答案

您需要通过item.thumbnail.sqDefault和item.thumbnail.hqDefault访问您的数据,因为它是一个名为props的对象。

You need to access your data via item.thumbnail.sqDefault and item.thumbnail.hqDefault since it's an object w/ named props.

更多推荐

本文发布于:2023-07-15 18:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117489.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:object   JavaScript   returning   Object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!