6paq 6paq - 5 months ago 12
JSON Question

Retrieving JSON from site equals 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
},

Answer

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