[英]json_decode returning empty array
我有一个curl命令,输出以下内容:
"{"meta":{"code":200},"data":{"username":"monstore","bio":"Art clothing line with our life scary tales as the imagination. info@heymonstore.com \/ +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"}}"
这是curl命令:
$output = curl_exec($ch);
基本上以上就是$ output打印出来的内容。 所以我尝试通过以下方式对此进行解码:
$userinfo = json_decode($output, false);
但是它返回一个空数组。 知道为什么吗?
$userinfo = json_decode($output, true);
您需要指定您想要一个关联数组,而不是json_decode中的对象:
$ userinfo = json_decode($ output,true); //您可以将其设置为true并尝试吗? 它为我工作。
从http://php.net/manual/en/function.json-decode.php ,如果为TRUE,则返回的对象将转换为关联数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.