Wondering if anyone can help? I'm playing around with some API from a website and well.. it outputs the data a bit messy! From the data below I'm basically trying to abstract the 'balance' so I can then echo it via PHP..
Requests_Response Object (
[body] => {"status_code":200,"status_message":"OK","result":{"balance":0.50}}
[raw] => HTTP/1.1 200 OK Server: nginx/1.10.2 Date: ### Content-Type: application/json Transfer-Encoding: chunked Connection: close Vary: Accept-Encoding X-Tracking-Token: ### Content-Encoding: gzip {"status_code":200,"status_message":"OK","result":{"balance":0.50}}
[headers] => Requests_Response_Headers Object ( [data:protected] => Array ( [server] => Array ( [0] => nginx/1.10.2 )
[date] => Array ( [0] => ### )
[content-type] => Array ( [0] => application/json )
[vary] => Array ( [0] => Accept-Encoding )
[x-tracking-token] => Array ( [0] => ### )
[content-encoding] => Array ( [0] => gzip ) ) ) [status_code] => 200 [protocol_version] => 1.1
[success] => 1
[redirects] => 0
[url] => ###
[history] => Array ( )
[cookies] => Requests_Cookie_Jar Object ( [cookies:protected] => Array ( ) ) )
Thanks!
dhruv jadia
1,6802 gold badges15 silver badges28 bronze badges
1 Answer 1
// $response is your Requests_Response Object
$body = json_decode($response->body, true);
if ($body['status_code'] == 200) {
echo $body['result']['balance'];
}
Comments
lang-php