我有一个使用Angularjs
和CodeIgnitor
构建的应用程序。 angularjs使用$scope
使用ng-init
在启动时使用Error: JSON.parse: end of data after property value in object
设置app.factory('FamilyFind', ['$resource', 'Data', function ($resource, Data) {
return $resource(Data.rootUrl + 'admin/family_find/:id', {id: '@id'},
{
query: {
isArray: true,
method: 'GET'
},
update: {
method: 'PUT'
}
}
);
}]);
// load serverside data using http resource service
FamilyFind.get({}, function (response) { // success
$scope.tableData = response.data; // store result to variable
}, function (error) { // ajax loading error
Data.errorMsg(); // display custom error notification
// error caught here
});
数据。
它的工作正常,数据较少,但应用程序因大量数据而失败。 GET响应中是否有任何数据大小限制,如GET参数限制?
错误:
function family_find_get($id = '', $type = 'json') {
$this->response->format = $type;
$family = $this->family_registration_model->find( $this->get() );
if($family) { // success
$this->response(array( 'data' => $family), 200);
} else { // error
$this->response(array( 'data' => array()), 200);
}
}
脚本:
function find($data) {
$query = "SELECT dev_members.name, dev_family.house_name, dev_family.house_no, dev_family.place,
dev_family.post, dev_family.phone,mem.male,mem.female
FROM dev_family
JOIN dev_members ON dev_members.id = dev_family.family_head_id
LEFT JOIN (SELECT family_id,SUM( gender = 'Male' ) AS male, SUM( gender = 'Female' ) AS female FROM dev_members) AS mem ON mem.family_id = dev_family.id WHERE dev_family.family_reg_no != ''";
if( isset($data['cluster']) && $data['cluster'] != '' ) {
$query.=" AND dev_family.cluster_id = ".$data['cluster']."";
}
$query = $this->db->query($query);
return $query->result();
}
我正在使用$resource service作为后端服务。
CodeIgnitor控制器:
{"data":[{"name":"abc","house_name":"dfdfgdfg","house_no":"1","place":"School Road","post":"dsfdfg","phone":"1111111","male":"278","female":"264"},{"name":"dgdfg","house_name":"dgdfg","house_no":"2","place":"School Road","post":"dfgdfg","phone":"111111","male":null,"female":null},{"name":"dgdfg","house_name":"dgdfg dgd","house_no":"3","place":"School Road","post":"dfgdg","phone":"11111","male":null,"female":null},{"name":"dgg","house_name":"dgdfg","house_no":"4","place":"School Road","post":"dggd","phone":"11111","male":null,"female":null}]
CodeIgnitor模型:
Error: Parse error on line 1:
...null,"female":null}]
-----------------------^
Expecting '}', ',', got 'EOF'
修改
当我从服务器端调试响应时,它显示主json对象没有自动关闭。查看从500多条记录中提取的样本数据
}
JSON格式化程序中的错误:
philsturgeon REST Controller library
当我使用RESTClient附加组件在最后$this->response(array( 'data' => $family), 200);
附近添加数据对象时,它工作正常。但是如何在服务器端解决这个问题呢?为什么它只发生在大数据上?
更新
我意识到问题出在echo json_encode(array('data'=>$family));
。而不是,
philsturgeon REST Controller library
我试过了,
{{1}}
现在它工作正常。任何人都知道如何在{{1}}中解决这个问题?
答案 0 :(得分:3)
我认为问题不在于数据大小本身。响应通常不受限制(尽管存在一些可能性,因为长时间的操作或任何其他原因服务器关闭连接并且客户端获得剪切数据)。
请最好检查一下您是否有正确的数据。我在以前的经验中遇到一些问题,当一些数据(通常是文本数据)与某些特殊符号(如',',''','{','}'等)可能会被破坏时。这取决于您的服务器端框架如何正确处理这些符号,以便客户端可以正确处理它。如果您可以将输出打印到服务器端的日志,并检查JSON数据的正确性。