php从对象中获取值

时间:2019-03-04 12:50:31

标签: php api object guzzle

我想从我从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;

我做错了什么?
谢谢

0 个答案:

没有答案
相关问题