简体   繁体   中英

How to access final balance from blockchain

I have the following url:

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

I want to access the final_balance from the output of the url.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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