簡體   English   中英

我如何從Coinmarketcap API獲取最新價格

[英]How can I get the last price from Coinmarketcap API

我正在嘗試從此硬幣中獲取美元的最新價格:

<?php

$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
echo $json;

?>

我在JSON對象上嘗試了兩個不同的選項,例如[0]['price]
什么都沒有。

來自coinmarketcap的響應是JSON,因此您需要json_decode

json_decode的第二個參數使您可以確定它是對象還是數組。 對於數組,將其標記為true

<?php

$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
$objResponse = json_decode($json, true);

echo $objResponse['data']['quotes']['USD']['price'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM