cannot use object of type stdClass as array ——PHP

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_15936309/article/details/87919474

分析原因:

  1. js传过来的字符串数据
  2. .php接收后转换为数组对象 $output = json_decode($cc);

    结果不彻底,里面的是个字符串对象。不能使用。故而报错:

    Cannot use object of type stdClass as array

解决方法:

两种

  1. 使用 json_decode($d, true)。就是使json_decode 的第二个变量设置为 true。$output = json_decode($cc,true);就可以
  2. json_decode($res) 返回的是一个对象, 不可以使用 $res['key'] 进行访问, 换成 $res->key 就可以了

猜你喜欢

转载自blog.csdn.net/qq_15936309/article/details/87919474