Extract data from Json url result php

260 Views Asked by At

I am trying to run a url for getting balance of a address.

URL: https://dogechain.info/api/v1/address/balance/DMr3fEiVrPWFpoCWS958zNtqgnFb7QWn9D

Which gives the JSON:

{
    "balance": "1682049.83191666",
    "success": 1
}

(Balance may vary time to time)

I am trying to extract the "balance" with the code:-

<?php
    $url = "https://dogechain.info/api/v1/address/balance/DMr3fEiVrPWFpoCWS958zNtqgnFb7QWn9D";
    $json = json_decode(file_get_contents($url), true);
    $balance = json("balance")

    echo $balance
?>  

But it returns nothing please help me =)

1

There are 1 best solutions below

0
On

You should do it like this

$balance = $json["balance"];
echo $balance;