我真的很灰白的头发。2 JSON。只有1个工作。 json_decode php
我想响应为https://api.gdax.com/products/btc-usd/ticker/
的[问]的数据,但它的返回NULL。
当我尝试使用几乎相同的JSON的另一个API,它工作完美。
此示例适用
<?php
$url = "https://api.bitfinex.com/v1/ticker/btcusd";
$json = json_decode(file_get_contents($url), true);
$ask = $json["ask"];
echo $ask;
这个例子返回null
<?php
$url = "https://api.gdax.com/products/btc-usd/ticker/";
$json = json_decode(file_get_contents($url), true);
$ask = $json["ask"];
echo $ask;
任何人那里有一个很好的解释,什么是错的代码返回null
将它分开,首先将'file_get_contents()'的结果存储在一个变量中,然后'echo'它来查看您实际从服务器返回的结果。如果你把这个添加到你的问题中,也许我们可以明白为什么'json_decode()'可能会遇到麻烦。 – rickdenhaan
代码没有错。服务器返回状态代码400 –