How to display Json data using PHP? -


i have json file , want display data in php file. tried code below not work.

$json_output = file_get_contents("https://gdata.youtube.com/feeds/api/playlists/pl3n6kxxrigdat31zif_7wlqtt3i20oqll?v=2&alt=jsonc"); $json = json_decode($json_output, true);   foreach($json->data->items->thumbnail $day) {     echo $day->sqdefault;    echo $day->hqdefault; } 

and json file

{"apiversion":"2.1","data":{"id":"pl3n6kxxrigdat31zif_7wlqtt3i20oqll","author":"tutorial top","title":"دورة سيو للمبتدئين [ali baba]","description":"","thumbnail":{"sqdefault":"https://i.ytimg.com/vi/xihvzqcvqhs/default.jpg","hqdefault":"https://i.ytimg.com/vi/xihvzqcvqhs/hqdefault.jpg"},"content":{"5":"http://www.youtube.com/p/pl3n6kxxrigdat31zif_7wlqtt3i20oqll"},"totalitems":31,"startindex":1,"itemsperpage":1,"items":[{"id":"plh_kl5fgjpmdcytgqamxfsvjj-pbr_yyic1y73r1tfyy","position":1,"author":"tutorial top","video":{"id":"kw8m5s2ohps","uploaded":"2013-11-10t16:04:28.000z","updated":"2014-02-18t17:59:36.000z","uploader":"vkd-nav91slmcynbkgjmsa","category":"people","title":"beginners seo tutorial course   intro","description":"","thumbnail": {"sqdefault":"https://i.ytimg.com/vi/kw8m5s2ohps/default.jpg","hqdefault":"https://i.ytimg.com/vi/kw8m5s2ohps/hqdefault.jpg"},"player":{"default":"https://www.youtube.com/watch? v=kw8m5s2ohps&feature=youtube_gdata_player","mobile":"https://m.youtube.com/details?v=kw8m5s2ohps"},"content":{"5":"https://www.youtube.com/v/kw8m5s2ohps?version=3&f=playlists&app=youtube_gdata","1":"rtsp://r8---sn-4g57kues.c.youtube.com/ciuleny73wiahan7hi4t5sypkxmydsanfegguglwbgf5bglzdhmm/0/0/0/video.3gp","6":"rtsp://r8---sn- 4g57kues.c.youtube.com/ciuleny73wiahan7hi4t5sypkxmyesarfegguglwbgf5bglzdhmm/0/0/0/video.3gp"},"duration":413,"aspectratio":"widescreen","rating":5.0,"likecount":"1","ratingcount":1,"viewcount":283,"favoritecount":0,"commentcount":0,"accesscontrol": {"comment":"allowed","commentvote":"allowed","videorespond":"moderated","rate":"allowed","embed":"allowed","list":"allowed", "autoplay":"allowed","syndicate":"allowed"}}}]}} 

i want output

sqdefault  |   hqdefault  https://i.ytimg.com/vi/kw8m5s2ohps/default.jpg,|https://i.ytimg.com/vi/kw8m5s2ohps/hqdefault.jpg 

firstly, if you'd access json structure object (as opposed array) drop second argument of json_decode(), otherwise end array $json. have @ first example see difference.
should loop through items array. each of elements has video property, has thumbnailproperty want

$json_output = file_get_contents("https://gdata.youtube.com/feeds/api/playlists/pl3n6kxxrigdat31zif_7wlqtt3i20oqll?v=2&alt=jsonc"); $json = json_decode($json_output); foreach ($json->data->items $item) {     echo $item->video->thumbnail->sqdefault;     echo $item->video->thumbnail->hqdefault; } 

should job. can see in action.

to clear picture of structure 1 of many online available json viewers ;-)


Popular posts from this blog