无法将stdClass类型的对象用作数组(php)
可能重复:
致命错误:无法将stdClass类型的对象用作
Possible Duplicate:
Fatal error: Cannot use object of type stdClass as array in
请继续获取此错误: 致命错误:无法在第31行的C:\ XAMMP \ xampp \ htdocs \ Yemi \ geograph \ table.php中将stdClass类型的对象用作数组
Please I keep getting this error: Fatal error: Cannot use object of type stdClass as array in C:\XAMMP\xampp\htdocs\Yemi\geograph\table.php on line 31
这是我要运行的php:
This is the php I am trying to run:
您实际上是在尝试以数组形式访问对象.
You are actually trying to access the object as array.
我可以猜测,当您使用json_decode
返回一个对象,并且在foreach
循环内尝试像关联数组一样访问它时,您会遇到问题.
I can guess you are having problem when you are using json_decode
which is returning an object and inside the foreach
loop you are trying to access it like an associative array.
将第二个参数作为true
传递给json_decode
强制其返回关联数组.
Passing the second argument as true
to json_decode
force it to return associative array.
进行以下更改.
更改此代码行
$items = json_decode($contents);
收件人
$items = json_decode($contents, true);