Search code examples
phpcurlphp-5.3

json_decode returning empty array


I have a curl command which outputs the following:

"{"meta":{"code":200},"data":{"username":"monstore","bio":"Art clothing line with our life scary tales as the imagination. [email protected] \/ +6281213162069 \/ BB PIN 293A4565","website":"http:\/\/www.heymonstore.com","profile_picture":"http:\/\/images.ak.instagram.com\/profiles\/profile_4472462_75sq_1354349840.jpg","full_name":"Monstore","counts":{"media":547,"followed_by":6472,"follows":129},"id":"4472462"}}"

Here's the curl command:

  $output = curl_exec($ch); 

Basically the above is what $output prints out. So I tried to decode this by doing:

$userinfo = json_decode($output, false);

however it returns an empty array. Any idea why?


Solution

  • $userinfo = json_decode($output, true);
    

    you need to specify you want an associative array instead of an object from json_decode: