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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With