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];
您的代码应为
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();