Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse json data form Youtube api

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?

like image 266
Mozart Brum Avatar asked Nov 25 '10 20:11

Mozart Brum


People also ask

How do I parse JSON in Rest assured?

We can parse JSON Response with Rest Assured. To parse a JSON body, we shall use the JSONPath class and utilize the methods of this class to obtain the value of a specific attribute. We shall first send a GET request via Postman on a mock API URL and observe the Response body.


1 Answers

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

like image 182
munchybunch Avatar answered Oct 28 '22 09:10

munchybunch