-2
請幫我把JSON數據 「price_usd」JSON幫助獲得內容
https://api.coinmarketcap.com/v1/ticker/bitcoin-cash/
[
{
"id": "bitcoin-cash",
"name": "Bitcoin Cash",
"symbol": "BCH",
"rank": "4",
"price_usd": "338.53",
"price_btc": "0.121547",
"24h_volume_usd": "189098000.0",
"market_cap_usd": "5579888431.0",
"available_supply": "16482700.0",
"total_supply": "16482700.0",
"percent_change_1h": "-4.29",
"percent_change_24h": "-23.79",
"percent_change_7d": "0.43",
"last_updated": "1501831807"
} ]
<?php
$json = file_get_contents('https://api.coinmarketcap.com/v1/ticker/bitcoin-cash/');
$data = json_decode($json, TRUE);
$price_usd = $data["price_usd"];
echo $price_usd;
?>
PHP腳本沒有什麼
的[?我如何從JSON中提取數據與PHP(可能的複製https://stackoverflow.com/questions/29308898/how-do-i-extract-data-from -json-with-php) –
查看數組make:print_r($ data); –
WORK:echo $ data [0] ['price_usd']; –