1
我是PHP新手,我只是想从JSON字典中获取一个值。这看起来很简单(至少对我来说),但我遇到了麻烦。我查看了JSON_decode
的PHP文档,我也看了一下“Parsing JSON data from a remote server”,但没有做到我想要的。它将我想要的字典项目返回为0,然后只是吐出JSON文件。然后我看了看“get data from JSON with php”,那只是什么都没有返回。如何使用PHP获取JSON数据
JSON例
{
"ask": 344.28,
"bid": 343.89,
"last": 343.97
}
一次尝试
$jsoncontent=file_get_contents("https://api.bitcoinaverage.com/ticker/global/USD");`
$priceusd=json_decode($json-content);
$lastusd=$priceusd['last'];
echo "Decoded JSON:\n";
echo "$priceusd\n";
echo "Raw JSON:\n";
echo "$jsoncontent\n";
第二次尝试
$result=file_get_contents("https://api.bitcoinaverage.com/ticker/global/USD");
$result = iconv('UTF-16', 'UTF-8', $result);
$json = json_decode($result);
echo $json->last;
我要的是价值JSON中的一个字典项目的URL。
谢谢!
您能否提供您正在使用的JSON的示例结构? – 2014-11-09 05:17:02
'{ “ask”:344.28, “bid”:343.89, “last”:343.97, }'我想回显最后一个值。 – Jake 2014-11-09 05:21:06
你的试验在哪里? – Ghost 2014-11-09 05:25:59