9

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?

1
  • What language are you trying to parse it in? Commented Nov 25, 2010 at 20:16

3 Answers 3

12

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

Sign up to request clarification or add additional context in comments.

3 Comments

I tryed this but got this response in firebug: data is not defined.
tahnk you, I found the error: description = response.data.items[0].description; You helped me a lot
@Mozart , do null check on data before start you accessing them
2

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.