我使用当前函数解析json文件:
function getRemoteJson($uri, $decode=true, $noob=false){
if($uri){
$fp = fopen($uri, "r");
$json = trim(file_get_contents($fp));
fclose($fp);
if($decode) return json_decode($json, true);
else return $json;
}
else return false;
}这个文件运行得很好:http://webcast-a.live.sportingpulse.com/matches/3886/09/18/90/33S64Il4cTaxQ/data.json
但是,当我使用它时,它会返回null:http://webcast-a.live.sportingpulse.com/matches/3886/09/18/94/84Q4GEVlZs4rg/data.json
解析此文件时没有错误代码(即json_last_error()返回JSON_ERROR_NONE )
当我使用在线工具检查文件格式时,文件会被解析.
如果你有任何线索的话谢谢
发布于 2013-11-10 08:31:08
好吧,我发现麻烦了..。我在另一台服务器上试了一下,发现了一个JSON_ERROR_UTF8错误。
因此,如果按以下方式修改代码:
function getRemoteJson($uri, $decode=true, $noob=false, $utf8_error = false){
if($uri):
$fp = fopen($uri, "r");
if($utf8_error) $json = utf8_encode(trim(stream_get_contents($fp)));
else $json = trim(stream_get_contents($fp));
fclose($fp);
$data = json_decode($json, true);
if(is_array($data)) return $data;
else
if(!$utf8_error) return getRemoteJson($uri, $decode, true, true);
else return false;
else:
return false;
endif;
}https://stackoverflow.com/questions/19873986
复制相似问题