Guzzle 使用破折号从 属性 中获取值?

Guzzle get value from property with dash symbol?

当我使用 Guzzle 发出请求时:

$response = json_decode($client->get($uri)->getBody()->getContents());

var_dump($response); die;

我在 var_dump 中得到了这个:

stdClass (object) [Object ID #2395][3 properties]
contacts: 
(array) [250 elements]
has-more: (boolean) true 
vid-offset: (integer) 111259

当我创建 $response->contacts 时,我得到了所有联系人,没有问题,但是这个 vid-offset 的名称中有一个 -,所以这不起作用:

$response->vid-offset

我也试过这个:

$response['vid-offset'];

我得到这个错误:Cannot use object of type stdClass as array

我也试过:

$response->getAttribute('vid-offset')

但是还是不行。

如何获取vid-offset属性的值?

你可以这样得到它:

$response->{'vid-offset'};