问题描述
在做extjsproxy实验的时候,报出了一个json数据格式的问题,麻烦各位大神给看下什么问题Ext.onReady(function(){Ext.define("User",{extend:'Ext.data.Model',fields:[{name:'id',type:'int'},{name:'name',type:'string'},{name:'age',type:'int'}]});varmyproxy=Ext.create('Ext.data.proxy.Ajax',{model:'User',reader:{type:'json'},url:"data/proxy/server.jsp"});varoperation=Ext.create('Ext.data.Operation',{action:'read'});myproxy.doRequest(operation,function(ope){//varres=ope.response.responseText;//varcount=ope.resultSet.totalRecords;//获取读取的远程数据的记录总数//varrecords=ope.reultSet.records;//获取记录数组alert("hello");});});
服务器返回的数据是:"[{id:1,name:'A',age:10},{id:2,name:'B',age:10}]"运行程序之后就报错,捕捉到的错误信息为:Ext.Error:UnabletoparsetheJSONreturnedbytheserver:You'retryingtodecodeaninvalidJSONString:[{id:1,name:'A',age:10},{id:2,name:'B',age:10}]
谢谢各位大神!!
解决方案
解决方案二:
[totalRecords:2,records:[{id:1,name:'A',age:10},{id:2,name:'B',age:10}]]服务器段返回的数据缺少记录数totalRecords