有没有json_decode的替代品?

JVE*_*999 0 php json

我有一个JSON字符串,它传递了http://www.freeformatter.com/json-validator.html中的检查,它返回:

The JSON input is valid in JavaScript.
The JSON input is valid according to RFC 4627 (JSON specfication).
Run Code Online (Sandbox Code Playgroud)

但是,当我跑:

$string = json_decode($string);
print_r($string);
Run Code Online (Sandbox Code Playgroud)

它打印字符串的方式与之前完全相同json_decode($string).

我还能尝试别的吗?或者也许是我不知道或没想过的事情?

字符串在这里:http://pubapi.cryptsy.com/api.php?method = marketdatav2


为了得到字符串,我正在使用:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://pubapi.cryptsy.com/api.php?method=marketdatav2");
$ret = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)

然后

$ret = substr($ret, 0,-1);
Run Code Online (Sandbox Code Playgroud)

因为它最后返回1,虽然我最初尝试了它而没有删除最后一个字符并得到相同的结果.

qwe*_*max 5

$s = file_get_contents("http://pubapi.cryptsy.com/api.php?method=marketdatav2");
$s = json_decode($s);

print_r($s);
Run Code Online (Sandbox Code Playgroud)

奇迹般有效

这是我的卷曲版本

$url = "http://pubapi.cryptsy.com/api.php?method=marketdatav2";
$ch=curl_init();
curl_setopt($ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
$data=curl_exec($ch);
curl_close($ch);

$s = json_decode($data);
print_r($s);
Run Code Online (Sandbox Code Playgroud)

  • 您必须使用CURLOPT_RETURNTRANSFER在varialbe获取数据,而你并不需要削减任何东西($ RET = SUBSTR($沤,0,-1);) (3认同)