是否可以使用PHP输出特定的JSON数据(从Firefox书签导出)。输出Firefox JSON数据
这是我到目前为止的代码,它将重新编码数据,因为Firefox不会以正确的UTF-8方式导出它。我也从文件末尾删除尾部。
<?php
// Read the file blah blah
$hFile = "../uploads/james.json";
$hFile = file_get_contents($hFile);
$hFile = utf8_encode($hFile);
// Remove the trailing comma because Firefox is lazy!!!!
$hFile = substr($hFile, 0, strlen($hFile)-3) . "]}";
$hDec = json_decode(fixEncoding($hFile));
foreach($hDec['uri'] as $hURI) {
// Output here
}
// Fixes the encoding to UTF-8
function fixEncoding($in_str) {
$cur_encoding = mb_detect_encoding($in_str);
if($cur_encoding == "UTF-8" && mb_check_encoding($in_str,"UTF-8")){
return $in_str;
}else{
return utf8_encode($in_str);
}
}
?>
我一直无法得到任何输出除了整个数据,使用var_dump。
那么这有可能吗? – 2009-05-24 20:52:45
我试图避免使用库,但如果这确实结束是唯一的选择,我会研究它。 – 2009-05-24 22:15:46