json - Foreach Loop PHP Error -


i want loop "textdisplay" using foreach im not sure part of php code wrong , gives me "trying property of non-object " error

xml

<pre> { "kind": "youtube#commentthreadlistresponse", "etag": "\"m2yskbqfythfe4irbtieogyyfbu/o6yjewn3uppkqc9x-zyya5xyha8\"", "pageinfo": {     "totalresults": 9,     "resultsperpage": 20 }, "items": [     {         "kind": "youtube#commentthread",         "etag": "\"m2yskbqfythfe4irbtieogyyfbu/ue9qsmedbkmeaurammww18vnqa8\"",         "id": "z12qxfxr2onpy1b5l04cdfzrgwabir0q4bo",         "snippet": {             "videoid": "au87oaj2jee",             "toplevelcomment": {                 "kind": "youtube#comment",                 "etag": "\"m2yskbqfythfe4irbtieogyyfbu/euv0uwlw788gwysvydo2xmrjg8w\"",                 "id": "z12qxfxr2onpy1b5l04cdfzrgwabir0q4bo",                 "snippet": {                     "authordisplayname": "randy taschner",                     "authorprofileimageurl": "https://yt3.ggpht.com/--ve0x3_vdcs/aaaaaaaaaai/aaaaaaaaaaa/p6kgycrpezw/s28-c-k-no-mo-rj-c0xffffff/photo.jpg",                     "authorchannelurl": "http://www.youtube.com/channel/uctrubhrb4brfcob-hmj6nnq",                     "authorchannelid": {"value": "uctrubhrb4brfcob-hmj6nnq"},                     "videoid": "au87oaj2jee",                     "textdisplay": "thank dan , envato creating video!",                     "textoriginal": "thank dan , envato creating video!",                     "canrate": true,                     "viewerrating": "none",                     "likecount": 1,                     "publishedat": "2015-08-16t05:02:25.000z",                     "updatedat": "2015-08-16t05:02:25.000z"                 }             },                 "canreply": true,                 "totalreplycount": 1,                 "ispublic": true         }     } ] 

}

my php code

 $json = file_get_contents('https://www.googleapis.com/youtube/v3/commentthreads?part=snippet%2creplies&videoid='.$videoid.'&key='.$apikey); $ytdata = json_decode($json); foreach($ytdata->items[0]->snippet->toplevelcomment->snippet->textdisplay $hit){     echo $hit; }

thanks

$ytdata->items[0]->snippet->toplevelcomment->snippet->textdisplay not array - it's string.

perhaps meant loop items?

foreach ($ytdata->items $item) {     echo $item->snippet->toplevelcomment->snippet->textdisplay; } 

Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -