从站点检索JSON等于NULL

$url="https://alcurex.com/api/market.php?pair=mrc_ltc&price=buy";

$json = file_get_contents($url);
$data = json_decode($json);

echo $json;
var_dump($data);

Results in a null response. However when you visit the page you get a html read out of

{
    "pair": MRC_LTC,
    "time": "2014-07-23 07:34:54,
    "price": 0.00000017,
    "volume": 558.99741176,
    "type": Buy
},

Response is not valid JSON format.

{ "pair": MRC_LTC, "time": "2014-07-23 07:34:54, "price": 0.00000017, "volume": 558.99741176, "type": Buy },

You could check it from Firefox console, correct JSON should be this:

var s = {
  "pair": "MRC_LTC",
  "time": "2014-07-23 07:34:54",
  "price": 0.00000017,
  "volume": 558.99741176,
  "type": "Buy"
 };

Errors:

  1. Missing " for pair, time and type
  2. Unnecessary comma at the end of string

You have three problems with this JSON:

  • pair value is not a valid type, if it should be string, it's missing quotes
  • time has string start quote but does not end it
  • type value is not a valid type, if it should be string, it's missing quotes

This is a valid JSON:

{
    "pair": "MRC_LTC",
    "time": "2014-07-23 07:34:54",
    "price": 0.00000017,
    "volume": 558.99741176,
    "type": "Buy"
}