[英]How can I get the last price from Coinmarketcap API
I'm trying to get the last price in USD from this coin: 我正在尝试从此硬币中获取美元的最新价格:
<?php
$json = file_get_contents('https://api.coinmarketcap.com/v2/ticker/2424/');
echo $json;
?>
I tried two different options on the JSON object like [0]['price]
我在JSON对象上尝试了两个不同的选项,例如
[0]['price]
Nothing works. 什么都没有。
The response from coinmarketcap is in JSON, so you need to json_decode it. 来自coinmarketcap的响应是JSON,因此您需要json_decode 。
The second paramter of json_decode lets you decide if its a object or array. json_decode的第二个参数使您可以确定它是对象还是数组。 For an array, mark this as true
对于数组,将其标记为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.