php - php从对象中检索值
问题描述
我想从从 API 调用响应接收到的 PHP 对象中检索特定值,但是我无法让它工作。
对象(主体)采用以下格式:
object(stdClass)#29 (2) {
["success"]=>
bool(true)
["result"]=>
object(stdClass)#19 (1) {
["events"]=>
array(1) {
[0]=>
object(stdClass)#4 (6) {
["id"]=>
int(743)
["tzShift"]=>
int(60)
["utcTime"]=>
int(1551703477)
["upTime"]=>
int(20953)
["event"]=>
string(14) "DisplayTouched"
["params"]=>
object(stdClass)#11 (4) {
["x"]=>
int(46)
["y"]=>
int(194)
["dx"]=>
int(0)
["dy"]=>
int(0)
}
}
}
}
}
我正在尝试通过以下方式检索值:
$body = json_decode($response->getBody());
$events = $body->result->events->params->x;
我究竟做错了什么?
谢谢
解决方案
推荐阅读
- javascript - 计算每行Jquery中的输入数组
- ios - 如何修复 Ionic (ios) 页面导航问题?
- azure - 使用 https://webchat.botframework.com/ 发送消息
- java - 如何用 Jackson 编写扁平化列表反序列化器?
- node.js - 谷歌驱动器更新图像中的 Node.js:错误:未授权客户端
- java - 在 couchbase 集群中添加节点后,Couchbase 客户端抛出 TimeoutException
- c++ - 使用从 B 继承的具体函数实现从 A 继承的虚函数
- c++ - 在 C 或 C++ 中从 X11 合成 WM 请求图像
- javascript - 通过函数确定负责函数调用的元素 ID。没有jQuery
- javascript - 为一个元素指定多个最大宽度值