[英]How to access a member of an stdClass in PHP
I have a JSON object that I decoded, and I can't access the element because it throws an error. 我有一个解码的JSON对象,由于该元素引发错误,因此无法访问该元素。
stdClass Object
(
[error] => InvalidRegistration
)
echo $device_response->error; // gives an error
How would I go about accessing attributes? 我将如何访问属性?
Below is whole array of response: 以下是整个响应数组:
stdClass Object
(
[multicast_id] => 5.3301797222004E+18
[success] => 1
[failure] => 3
[canonical_ids] => 0
[results] => Array
(
[0] => stdClass Object
(
[message_id] => 0:1388910534147789%25796c83f9fd7ecd
)
[1] => stdClass Object
(
[error] => InvalidRegistration
)
[2] => stdClass Object
(
[error] => InvalidRegistration
)
[3] => stdClass Object
(
[error] => InvalidRegistration
)
)
)
Below is how I am accessing it: 以下是我的访问方式:
foreach ($responseBody->results as $device_response) {
echo $device_response->error;
}
$obj = new stdClass();
$obj->foo = "var";
echo $obj->foo;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.