如何用php从嵌套数组中获取API数据

如何用php从嵌套数组中获取API数据,php,json,api,Php,Json,Api,我想按照下面的代码从数组内部的数组中获取数据: {"address":"0x64890972513558cb4e4b4a7f8af48d892fd097b7","ETH":{"**balance**":0,"totalIn":0,"totalOut":0},"countTxs":0,"tokens":[{"**tokenInfo**":{"**address**":"0xad640689e6950b7453729a4686edb3fdfd754616","**name**":"CIChain",

我想按照下面的代码从数组内部的数组中获取数据:

{"address":"0x64890972513558cb4e4b4a7f8af48d892fd097b7","ETH":{"**balance**":0,"totalIn":0,"totalOut":0},"countTxs":0,"tokens":[{"**tokenInfo**":{"**address**":"0xad640689e6950b7453729a4686edb3fdfd754616","**name**":"CIChain","decimals":"18","symbol":"CIC","totalSupply":"3000000000000000000000000000","owner":"0xecb64b92ffb5179b47c87d2f105d6eeebb132c68","lastUpdated":1527246490,"issuancesCount":0,"holdersCount":31528,"**price**":false}
我正在使用以下步骤,但无法继续:

    $address = "0x64890972513558cb4e4b4a7f8af48d892fd097b7"; //$_POST['address'];


$scan_url = 'https://api.ethplorer.io/getAddressInfo/'.$address.'?apiKey=freekey';
$scan_json = file_get_contents($scan_url);
$scan_array = json_decode($scan_json, true);
foreach($scan_array['tokens'] as $key => $eth) { 
    foreach($eth['tokenInfo'] as $key => $etth) {  

  echo $etth['name'];  
}}

我想将星号标记的日期**检索到php中的echo中,那么如何获取嵌套数据。

根据您的url,如果您需要更改代码,如下图所示

$scan_array = json_decode($scan_json, true);
foreach($scan_array['tokens'] as $key => $eth) { 
    echo $eth['tokenInfo']["name"]. "\n";
}


第二个
foreach
提供了来自
tokenInfo
的所有元素,因此无需使用内部
foreach
或获取所有元素,无需使用类似
$etth['name']
这样,只有
$etth
提供就足够了。

试试
json\u decode($json)->balance
谢谢你,效果很好,如果我想得到数组{“address”:“0x64890972513558cb4e4b4a7f8af48d892fd097b7”,“ETH”:……}只要使用
$scan\u数组[“address”]
我得到了以下错误警告:为C:\AppServ\www\Airdrop\scan.php中的foreach()提供的参数无效,第9行