DataTables JSON编码上的未终止字符串

时间:2017-11-02 14:07:26

标签: php json codeigniter

当我尝试使用DataTables JQuery插件时,我遇到了一个问题。

SyntaxError: JSON.parse: unterminated string at line 1 column 1572865 of the JSON data

我认为这是我从3000行查询中切割的大型数据库中编码JSON的方式,因为如果我一次性执行此操作,则会出现内存不足错误:

$rowNum = $this->db->query("SELECT ID WHERE CONDITION")->result_array();
$pas = 3000;
for($i = $rowNum[0]; $i < count($rowNum); $i = $i+$pas) { // Loop wrinting rows 3000 per 3000 in a JSON
    $begin = $rowNum[$i];
    $end = (empty($rowNum[$i+($pas-1)])) ? end($rowNum) : $rowNum[$i+($pas-1)];
    $query = "
            LARGE QUERY FOR HAVING THE WHOLE TABLE AND ID BETWEEN {$begin} AND {$end} ";
    $rows = $this->db->query($query)->result_array();
    $line = json_encode($rows);
    file_put_contents(FCPATH."application/ajax/GuyaforTable_brut.json", $line, FILE_APPEND | LOCK_EX);
}
$charMappings = [
    '][' => ',',
];
$content = file_get_contents(FCPATH."application/ajax/GuyaforTable_brut.json");
file_put_contents(FCPATH."application/ajax/GuyaforTable_brut.json", strtr($content, $charMappings));

JSON的第1行第1572865行:

... 
,{"NomForet":"Paracou","n_parcelle":"17","n_carre":"2","n_arbre":"1081.0","Surface":"6.25","i_arbre":"167370","X":"232.0","Y":"156.0",
"Xutm":"272952.1 -> 6 <- ",
"Yutm":"586592.38","UTMZone":"22","Lat":"5.3035345","Lon":"-53.048702","n_essence":"751","nomPilote":"mesupu","Densite":"1.1000000000000001","circonf":"60.0","code_vivant":"1","code_mesure":"0","campagne":"1995","circ_corr":"60.0","code_corr":"0","Famille":"Melastomataceae","Genre":"Miconia","Espece":"tschudyoides","Commerciale":"0","SourceBota":"Vern","indSurete":"-1.0"},{"NomForet"
...

1 个答案:

答案 0 :(得分:1)

不确定这是否仍然是您的问题,但是如果您在Firefox devtools中遇到该错误,似乎将在即将发布的版本(61)中修复:https://bugzilla.mozilla.org/show_bug.cgi?id=1223726

devtools正在截断一定大小的响应(不影响实际代码)。