json解析后得到的是object(stdClass)类型,转array类型

在线json解析工具:http://json.parser.online.fr/

array通过json_encode()方法编码再经过json_decode($json)方法解析后变成stdClass类型

解决方法:使用json_decode()方法的时候,带上第二个参数:json_decode($json,true)

参考:

mixed json_decode ( string $json [, bool $assoc ] )
接受一个 JSON 格式的字符串并且把它转换为 PHP 变量

参数

json
待解码的 json string 格式的字符串。

assoc
当该参数为 TRUE 时,将返回 array 而非 object 。

原文地址:https://www.cnblogs.com/junxu/p/5016211.html