0

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?

2
  • How do you know it's an empty array? This seems to work from 5.2 and up: 3v4l.org/0hYjb Commented Sep 26, 2013 at 4:24
  • echo $output prints exactly one string that you wrote? If so, you have two extra quote-signs " (at the start and at the end) Commented Sep 26, 2013 at 4:25

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

$userinfo = json_decode($output, true); //could you set this to true and try? It worked for me.

From http://php.net/manual/en/function.json-decode.php, When TRUE, returned objects will be converted into associative arrays.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.