Alamri
Alamri

Reputation: 2182

Parse JSON from array

I have this JSON response from YouTube v2: http://gdata.youtube.com/feeds/api/users/youtube/uploads?orderby=published&max-results=1&alt=json.

It only returns with one video entry as I wanted. I want to get the title of that video? I have currently used the following code:

$URL = file_get_contents('http://gdata.youtube.com/feeds/api/users/youtube/uploads?orderby=published&max-results=1&alt=json');
$readjson = json_decode($URL);
$title = $readjson->{'feed'}->{'entry'}->{'title'}->{'$t'};
echo $title;

but it looks like it's not a normal JSON tree, because it has an array in video entry so my code didn't work. Any ideas how to get that?

Upvotes: 0

Views: 118

Answers (1)

webphp
webphp

Reputation: 102

$title = $readjson->{'feed'}->{'entry'}[0]->{'title'}->{'$t'};

Upvotes: 2

Related Questions