我已经浏览了所有相关帖子,使用json调用从jsp加载我的jqGrid。但我无法成功。谁能告诉我哪里错了? JAVASCRIPT CODE
$("#grid").jqGrid({
url:'dhypo/featurelist.jsp',
datatype: 'json',
autowidth: true,
colNames:['ColOne','ColTwo'],
colModel:[{name:'id',index:'id'},
{name:'name',index:'name'}
],
datastr: mygrdata,
rowNum:5,
rowList:[5,7,10],
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
multiselect: false,
caption:"JSPJSON",
jsonReader:{
repeatitems: true,
cell: "cell",
id: "id",
root: "rows",
page: function (obj) { return 1; },
total: function (obj) { return 1; },
records: function (obj) { return obj.length; }
}
});
JSP CODE是
<%@ page language="java" contentType="application/json;" pageEncoding="UTF-8"%>
<%
JSONObject responsedata = new JSONObject();
JSONArray cellarray = new JSONArray();
try{
responsedata.put("total",10);
responsedata.put("page",1);
responsedata.put("records",50);
net.sf.json.JSONObject cellobj=new net.sf.json.JSONObject();
String valaray[] = {"One","Two","Three"};
net.sf.json.JSONArray cell=new net.sf.json.JSONArray();
int cnt = 1;
for(int i=0; i<valaray.length; i++){
cellobj.put("id",cnt);
cell.add(cnt);
cell.add(valaray[i]);
cellobj.put("cell",cell);
cell.clear();
cellarray.add(cellobj);
cnt++;
}//for
responsedata.put("rows",cellarray);
out.println(responsedata);
System.out.println("JSON DATA.."+responsedata);
}catch(Exception exp){
System.out.println("Exception FROM ........"+exp);
responsedata.put("rows",cellarray);
out.println(responsedata);
}
%>
从jsp打印的JSON DATA是..... { “总”:10, “页”:1, “记录”:50, “行”:[{ “ID”:1, “小区”:[1, “一”]},{ “ID”:2 , “细胞”:[2, “二”]},{ “ID”:3, “小区”:[3, “三”]}]}
我的jqgrid没有与数据混淆。表结构/寻呼机正在显示。 - 我试图将类型更改为'jsonstring'并使用生成的jason数据,它正在工作,所以我认为json数据是有效的。
有人可以帮我弄清楚这里有什么问题吗?