I’m trying to read twitch.tv API, but something is wrong.
This is the JSON data I get as a response:
http://pastebin.com/uzx4LXJg
This is the PHP codes.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.twitch.tv/kraken/streams?game=League+of+Legends");
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_NOBODY, FALSE);
curl_setopt($curl, CURLOPT_REFERER,"");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$json_array = json_decode($response, true);
echo $json_array['streams']['viewers'] . 'aaa';
It just shows “aaa”.
What am I doing wrong?
steamsis an array of objects, not a single object. You need to pick an index (or use a for loop).