简体   繁体   English

如何从区块链获取最终余额

[英]How to access final balance from blockchain

I have the following url:我有以下 url:

https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1

I want to access the final_balance from the output of the url.我想从 url 的 output 访问 final_balance。

I have the following code:我有以下代码:

 $value = file_get_contents($url);
    $FinalBalance = $value["final_balance"];
    var_dump($FinalBalance);

Error PHP Warning:  Illegal string offset 'final_balance'

I also tried the following code:我还尝试了以下代码:

 $value = file_get_contents($url);
    $json = json_decode($value);
    var_dump($json);
        $FinalBalance = $json["final_balance"];
    var_dump($Final_Balance);
Error PHP Fatal error:  Uncaught Error: Cannot use object of type stdClass as array

Your are near to finish that stuff but I will write down desired solution.您即将完成这些工作,但我会写下所需的解决方案。 Please have a look.请看一看。

 $url="https://blockchain.info/multiaddr?active=1AT4ES3ee1N6iBzzbdK8xvcAV3CBTRKcbS|1FHcYth4LRJMwNx2y8NR5DH7sYCiVzXs3Y&n=1";
 $value = file_get_contents($url);
 $FinalBalance = $value;
 $data=json_decode($FinalBalance);
 echo $data->wallet->final_balance;
 echo $data->addresses[0]->final_balance;
 echo $data->addresses[1]->final_balance;
 exit;

You are going to access the inner object so you have to provide proper reference whether it is an array or an object.您将访问内部 object,因此您必须提供正确的引用,无论它是数组还是 object。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM