通过API处理数据


Processing data got throught API

读了一段时间关于通过API处理数据的文章,但运气不佳。要么显示完整的api响应,要么什么都不显示。

API响应如下:

{"status":"success","data":{"address":"198aMn6ZYAczwrE5NvNTUMyJ5qkfy4g3Hi","balance":8000.00033346,"balance_multisig":0},"code":200,"message":""}

我的处理代码是:

$url = "http://btc.blockr.io/api/v1/address/balance/198aMn6ZYAczwrE5NvNTUMyJ5qkfy4g3Hi";
$website = file_get_contents($url);
$result = json_decode($website);
printf($result["data"]["balance"]);

你知道我做错了什么吗?

我只需要获取余额部分

尝试

printf($result->data->balance);

$result = json_decode($website, true);  // When the second parameter is TRUE, returned objects will be converted into associative arrays. 
printf($result["data"]["balance"]);

阅读手册也有帮助。