【发布时间】:2023-03-28 12:17:01
【问题描述】:
我正在尝试使用以下脚本获取比特币的"price"。本质上,它访问 coinmarketcap api 并打印出比特币的价格。但是,我不确定此错误的含义或如何修复它
我的代码
<?php
$url = "https://api.coinmarketcap.com/v2/ticker/";
$contents = file_get_contents($url);
$decode_content = json_decode($contents);
$myprice = $decode_content->data->1->name;
echo "Price: " . $myprice;
?>
错误信息
Fatal error: Cannot use object of type stdClass as array
【问题讨论】:
标签: php json echo file-get-contents