9
votes

I have to parse the json data from this url http://gdata.youtube.com/feeds/api/videos?q=aNdMiIAlK0g&max-results=1&v=2&alt=jsonc using jquery. I have to extract the media:title and description of the video. Anyone know how do that?

3
What language are you trying to parse it in?Corey Farwell

3 Answers

12
votes

You're probably looking for jQuery.getJSON(): http://api.jquery.com/jQuery.getJSON/

var url = "http://gdata.youtube.com/feeds/api/videos?q=aNdMiIAlK0g&max-results=1&v=2&alt=jsonc";
var title;
var description;
$.getJSON(url,
    function(response){
        title = response.data.items[0].title;
        description = response.data.items[0].description;
});

getJSON returns a response with property data, and data has a property of items which is an array. The array only has one item, so we're just using items[0], and that item has a property title and a property description that we're going to save into our variables.

Hope this helps!

//edit: oops, yeah I thought response would be a better name for the variable, forgot to update the second line

2
votes

Try this..

$.ajax({
   url: http://gdata.youtube.com/feeds/api/videos?q=aNdMiIAlK0g&max-results=1&v=2&alt=jsonc,
   dataType: 'json',
   data: data,
   success: your_callback
 });
0
votes

I created a JavaScript function to pull and display a YouTube channel listing (posted the code to StackOverflow). You can find it here:

Getting all videos of a channel using youtube API