我的PHP代码究竟出了什么问题?

时间:2014-10-03 07:13:21

标签: php html

好的,在acc = BURST-KHTJ-G3H7-LD2Q-H7LJ6时进行api调用。

这是来自json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAccount&account=".$_GET['acc']))

的第一个数组
{
"publicKey": "231add65e7233e8df06debe3e71f161cb8975d21c9f9ee6e52f4868f524cb64d",
"assetBalances": [
    {
        "asset": "15295227971848272658",
        "balanceQNT": "4205"
    },
    {
        "asset": "11375670541237055652",
        "balanceQNT": "15"
    }
],
"guaranteedBalanceNQT": "0",
"balanceNQT": "5465615075791",
"name": "Irontiga",
"accountRS": "BURST-KHTJ-G3H7-LD2Q-H7LJ6",
"unconfirmedAssetBalances": [
    {
        "unconfirmedBalanceQNT": "4205",
        "asset": "15295227971848272658"
    },
    {
        "unconfirmedBalanceQNT": "15",
        "asset": "11375670541237055652"
    }
],
"account": "17456591454562991920",
"effectiveBalanceNXT": 0,
"unconfirmedBalanceNQT": "4870615075791",
"forgedBalanceNQT": "0"

}

然后是

中的数组
json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".assetBalance))



{
"decimals": 1,
"numberOfTrades": 58,
"asset": "15295227971848272658",
"quantityQNT": "1000000",
"description": "Shares in BURST pool. See https://burstforum.com/index.php?threads/the-big-announcement.149/ for more details",
"name": "HardInvest",
"accountRS": "BURST-T7BK-USTG-KVKC-D2RDL",
"account": "13343849956527346993"

}

我的代码看起来像这样

<!DOCTYPE html>
<html>
<head>
</head>
<body>

<?php
    $account = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAccount&account=".$_GET['acc']));
    foreach($account->assetBalances as $assetBalance)
    {
        $assetInfo = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".$assetBalance));
        echo $assetInfo['name'];
        echo "<br>"
    }

?>
</body>
</html>

但只是不工作,为什么不呢?

2 个答案:

答案 0 :(得分:1)

如果字符串为此添加适当的引用,请尝试将assetBalance替换为$assetBalance变量而不是字符串

$assetInfo = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".$assetBalance));

如果它的字符串尝试

$assetInfo = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=assetBalance"));

答案 1 :(得分:0)

我忘了在$assetBalance->asset

的位置下添加$assetInfo = json_decode(file_get_contents("http://127.0.0.1:8125/burst?requestType=getAsset&asset=".$assetBalance));

显然其他答案也有帮助;)