处理ErrorException(E_NOTICE)未定义偏移量:0

时间:2019-12-17 03:58:17

标签: api laravel-5 guzzlehttp

I am trying to access the elements within the text JSON reference from the call, for example, I am trying to access the item (content)
     

在JSON内,但继续显示错误消息   该代码有效,并显示JSON文件的全文   没问题是否有类似的PHP lavarel方法可以   用作arrylist或用于   获取响应中的元素

$client = new Client();
$request = $client->post('http://localhost:4567/user/login', [
                'headers' => ['Content-Type' => 'application/json'],
                'body' => json_encode($data),
          ]);
$request= json_decode($request->getBody(), true);
return $request[0];

1 个答案:

答案 0 :(得分:0)

您的代码应该像

use GuzzleHttp\Client;

$client = new Client();
    $request = $client->post('http://localhost:4567/user/login', [
                'headers' => ['Content-Type' => 'application/json'],
                'body' => json_encode($data),
            ]);
 return $request->getBody();