Reputation: 2570
I'm using Guzzle to get an HTTP response. If I do this:
$response = $res->getBody();
I get an object with 'email' as one of the properties. But if I do either:
$email = $res->getBody()->email;
or
$email = $response->email
I get a 'No value for email' error. What am I missing?? How can I access a specific property in the response object?
Upvotes: 3
Views: 2356
Reputation: 36924
The getBody
method returns an instance of StreamInterface. You first need to retrieve the contents of the response:
$response = (string) $res->getBody();
Only then you can decode the json payload:
$json = json_decode($response);
$email = $json->email;
Upvotes: 7