I am trying to use the PHP function json_decode to get a specific value from a json object. Sample code below:
foreach ($streams as &$i) { $chan = "http://api.justin.tv/api/stream/list.json?channel=" . $i; $json = file_get_contents($chan); //Turns the gathered file information into a string for searching purposes. echo $json . " End of json variable.<br>"; $exist = strpos($json, 'name'); // Search the file/json object for the name attribute if($exist) { // Check to see if a name existed and if so add it to the live streams and get the image. echo " <a href=\"http://justin.tv/" . $i . "\">" . $i . "</a> <br>"; $liveStreams[$count] = $i; $json_information = json_decode($json,true); $image[$count] = $json_information[0]['channel']['image_url_large']; echo "Image link should appear: " . $image[count]; $count++; } }
So, what I'm trying to do with this, first of all, we collect which threads are active from the list presented earlier in the code. Secondly, if the stream is active, display a link to the page to view it (currently the stream is justin.tv). Currently, only live broadcasts with links to them work. I need to find out why, after decoding, I can not access the image_url_large variable. Ultimately, this will be a preview of the stream thumbnails.
I looked at various places for what was supposed to work, and even in stackoverflow I saw the following stream:
json decode in php
I tried to do this as an answer to nickf, and it still doesn't work. Any help would be greatly appreciated, and would also remain in array style instead of going into objects.
source share