将session里的json字符串转换为数组
//a:3:{s:4:"name";s:6:"huqian";s:3:"sex";s:3:"男";s:3:"age";i:27;}
$whereSql = json_decode(getSession('whereSql'));
$whereSql['name'];

出现错误:
Cannot use object of type stdClass as array

解决方法(2种):
1、使用 json_decode($d, true)。就是使json_decode 的第二个变量设置为 true,转换为数组
2、json_decode($res) 返回的是一个对象, 不可以使用 $res['key'] 进行访问, 换成 $res->key 就可以了

Last modification:May 5, 2020
如果觉得我的文章对你有用,请随意赞赏