如何显示24H Volume Coinmarketcap API

时间:2018-01-06 05:26:27

标签: php api

您好我在coinmarketcap api中显示24 H音量名称时出现问题,当我调用它时会产生错误,但其他值正常工作可能是因为24h音量以数字开头。我想知道我将如何得到它。谢谢。这是我目前的代码

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


<table>
<tbody>
<tr>
<th>Name</th>
<th>Symbol</th>
<th>Rank</th>
</tr>
<?php   
ini_set('max_execution_time', 300);
// $tick = file_get_contents('https://api.coinmarketcap.com/v1/ticker/bitcoin/');
$url ='https://api.coinmarketcap.com/v1/ticker/?start=0&limit=1000';// path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data); // decode the JSON feed

// echo $characters[0]->name;

foreach ($characters as $character) {
echo '<tr>';
echo '<td>' . $character->name . '</td>';
echo '<td>' . $character->symbol . '</td>';
echo '<td>' . $character->rank . '</td>';
echo '<td>' . $character->price_usd . '</td>';
echo '<td>' . $character->price_btc . '</td>';
echo '<td>' . $character->total_24h_volume_usd . '</td>';

echo '<td>' . $character->market_cap_usd . '</td>';
echo '<td>' . $character->available_supply . '</td>';
echo '<td>' . $character->total_supply . '</td>';
echo '<td>' . $character->max_supply . '</td>';
echo '<td>' . $character->percent_change_1h . '</td>';
echo '<td>' . $character->percent_change_24h . '</td>';
echo '<td>' . $character->percent_change_7d . '</td>';
echo '<td>' . $character->last_updated . '</td>';

echo '</tr>';
}
?>
</tbody>sdsdf
</table>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

要访问该fashoin中指定的字段,您需要使用{''}包装它们。所以你需要写$character->{'24h_volume_usd'}