Today, I debugged a php program and found an unexpected error. the error code is CannotuseobjectoftypestdClassasarray. What's going on? After checking for half a day, I found that this was actually a json writing problem:
Today, I debugged a php program and found an unexpected error. Error Code: Cannot use object of type stdClass as array. What's going on? After checking for half a day, I found that this was actually a json writing problem:
Cause:
$ Res = json_decode ($ res );
$ Res ['key']; // use the object after json_decode () as an array.
The following two solutions are provided on the Internet:
1. use json_decode ($ d, true ). The second variable of json_decode is set to true.
2. json_decode ($ res) returns an object. you cannot use $ res ['key'] for access. you can replace it with $ res-> key.
Reference Manual: json_decode
Return Values: Returns an object or if the optional assoc parameter is TRUE, an associative array is instead returned.