将url中的json数据读入变量

时间:2017-11-08 19:05:08

标签: php json

这适用于所有货币。我可以输出'0','1','2',...

的所有数据
$url = 'https://bittrex.com/api/v1.1/public/getmarketsummaries
$response = file_get_contents($url);
$obj = json_decode($response,true);

$marketname = $obj['result'][0]['MarketName'] . '';

此网址是针对带有“市场”字符串的单一货币。

https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-neo

但我怎么能读到这个?

$url = 'https://bittrex.com/api/v1.1/public/getmarketsummaries?market=btc-neo
$response = file_get_contents($url);
$obj = json_decode($response,true);

$marketname = $obj['result'][0]['MarketName'] . '';

不起作用!

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

来自API

使用单数summary代替summaries来过滤市场

$url = 'https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-neo'

答案 1 :(得分:0)

有它:

相反:

$url = 'https://bittrex.com/api/v1.1/public/getmarketsummaries?market=btc-neo';

此:

$url = "https://bittrex.com/api/v1.1/public/getmarketsummary?market=btc-neo";

关键还是"而不是'

感谢所有人!