1

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
asked Dec 28, 2016 at 3:43

1 Answer 1

1
// $response is your Requests_Response Object
$body = json_decode($response->body, true);
if ($body['status_code'] == 200) {
 echo $body['result']['balance'];
}
answered Dec 28, 2016 at 3:52

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.