想知道是否有人可以提供帮助?我正在玩一个来自网站的API并且很好..它输出的数据有点乱!从下面的数据中我基本上试图抽象出平衡'所以我可以通过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 ( ) ) )
谢谢!
答案 0 :(得分:1)
// $response is your Requests_Response Object
$body = json_decode($response->body, true);
if ($body['status_code'] == 200) {
echo $body['result']['balance'];
}