我无法从下面的页面上显示数据price_usd
<?php
$url = "https://api.coinmarketcap.com/v1/ticker/bitcoin";
$json = json_decode(file_get_contents($url), true);
$price = $json["price_usd"];
echo $price;
?>
不确定我做错了什么。
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "2451.36",
"price_btc": "1.0",
"24h_volume_usd": "726987000.0",
"market_cap_usd": "40298274744.0",
"available_supply": "16439150.0",
"total_supply": "16439150.0",
"percent_change_1h": "-1.7",
"percent_change_24h": "-3.89",
"percent_change_7d": "-4.33",
"last_updated": "1499697854"
}
]
由于
造币
答案 0 :(得分:1)
您的JSON对象 $ json 是一个包含一个项目的数组, 要获得price_usd,请尝试:
$price = $json[0]["price_usd"];