代码之家  ›  专栏  ›  技术社区  ›  lewis4u

Guzzle从带有短划线符号的属性中获取值?

  •  1
  • lewis4u  · 技术社区  · 6 年前

    当我向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')
    

    但它仍然不起作用。

    如何获取 补偿偏移 财产?

    1 回复  |  直到 6 年前
        1
  •  4
  •   Alexandre Elshobokshy    6 年前

    你可以这样做:

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