Recover Json Value

Asked

Viewed 98 times

0

I am including on my website my Youtube channel with the videos. But there is a part of Json that I’m not getting back.

I’m doing like this:

$.each($feed.items, function(i,item){
var url = item.videoId;

I commented in the code the line for you to see from Json. But it’s coming Undefined.

{
 "kind": "youtube#searchListResponse",
 "etag": "\"***/***"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 9,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"***/***"",
   "id": {
    "kind": "youtube#video",
    "videoId": "*************" ############################## AQUI
   },
   "snippet": {
    "publishedAt": "2015-05-26T17:47:49.000Z",
    "channelId": "****",
    "title": "TITULO",
    "description": "",
    "thumbnails": {
     "default": {
      "url": "default.jpg"
     },
     "medium": {
      "url": "qdefault.jpg"
     },
     "high": {
      "url": "hqdefault.jpg"
     }
    },
    "channelTitle": "TESTE",
    "liveBroadcastContent": "none"
   }
  },

  • Try to do so: var url = item.items.videoId;.

  • 1

    So there’s no way. I managed to solve it. I gave one console.log(item) and saw how he was returning. I will post.

  • Diego, if possible post the solution and then mark as accepted. =)

  • 1

    Not for two days.

1 answer

1


I solved the question. Although this Json above is the one returned by the direct URL in the browser, I opened mine Inspect Element and gave a console.log(item) within the function Each().

Then he showed me:

Object = Item {
   id : {
      videoId: *****
   }
}

Then I made a item.id.videoId and it worked great.

Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.