一、json_encode和json_decode区别
1、json_encode:对象/数组 ---> json
2、json_decode:json ---> 对象/数组
二、json_decode转化为数组
转化为数组时,第二个参数很重要:不加true会以PHP对象输出, 加true输出PHP数组,默认值为false
即:json_decode($str,true);
不加true时:
stdClass Object ( [data] => stdClass Object ( [access_token] => 3df2e217-fc2c-41b0-ae1f-b6da665e61ab [expires_in] => 604800 [refresh_token] => a3e7b36e-ecf7-4678-9f94-4d2bf16c4f8a [scope] => SCOPE [shop_id] => 1441968 [shop_name] => 吉祥传承饰品 ) [err_no] => 0 [message] => success )
加true时:
Array ( [data] => Array ( [access_token] => 3df2e217-fc2c-41b0-ae1f-b6da665e61ab [expires_in] => 604800 [refresh_token] => a3e7b36e-ecf7-4678-9f94-4d2bf16c4f8a [scope] => SCOPE [shop_id] => 1441968 [shop_name] => 吉祥传承饰品 ) [err_no] => 0 [message] => success )
|