Lukeidiot Posted May 21, 2015 Share Posted May 21, 2015 Hello I am trying to output the titles of each of the 10 results provided in the following JSON URL: https://www.googleapis.com/youtube/v3/search?part=snippet&q=test&maxResults=10&key=AIzaSyCoSXBJjRh7ToEJIMH2QF1-UsgK71E_RQ4 function populateRelated(searchTerm){ var search_input = searchTerm; var keyword = encodeURIComponent(search_input); var yt_url2 = 'https://www.googleapis.com/youtube/v3/search?part=snippet&q=' + keyword + '&maxResults=10&key=AIzaSyCoSXBJjRh7ToEJIMH2QF1-UsgK71E_RQ4'; $.getJSON(yt_url2, function(data) { $.each(data, function(i,v){ $('#relatedsongs').append('<a class="dl" href="#" style="font-size: 12px;">' + items[0].id.videoId + '</a><br>'); console.log('worked'); }); }); } The upper code DOES NOT work. Any idea how I can get it to output the titles for the results only? ExampleVideo Title 1 Video Title 2 Video Title 3 ... Video Title 10 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/296435-eachjson-with-multidimensional-array/ Share on other sites More sharing options...
Solution requinix Posted May 21, 2015 Solution Share Posted May 21, 2015 The data is the entire response, not just a part of it. The items array is at .items and that's what you should be looping over. Inside the function, v will be one of the items and you should use .id.videoId on that. Quote Link to comment https://forums.phpfreaks.com/topic/296435-eachjson-with-multidimensional-array/#findComment-1512368 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.