Get()方法获取特定的数据返回后的回调

时间:2019-01-25 23:23:32

标签: php json guzzle

我正在一个项目上,遇到一个问题,请解释:

我正在使用Guzzle http向网络服务器执行POST,并遵循:

     public function sendPost($direction, array $data, array 
     $options = ['http_errors'=>false])
  {
        $url = $this->interpolate( self::BASE_PATH."/{direction}", 
  [
        'direction'  => $direction
    ]);

    $options = array_merge($options,['body'=>json_encode($data)]);

    return $this->client->post($url, $options);
}

该方法正常工作,我返回以下内容:

{     “ id”:“ jdhj9h830027hd73hs9q9js9”,     “ direction”:“向左”,     “ status”:“成功”,     “代码”:{         “ id”:“ 1”,         “ desc”:“确定”,         “错误”:错误,         “ msg”:空     } }

我不能做的是以下事情:

仅返回给定的“ jdhj9h830027hd73hs9q9js9”(即“ id”参数)的方法。

有人可以帮助我吗?

PS。通过使用“ sendPost()”方法,我可以分别访问所需的数据,但是我无法通过其他方法(例如“ getId()”)来进行此操作。

预先感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

只需尝试:

return ($this->client->post($url, $options))->id;
相关问题