Java JqGrid未从JSON加载数据

Java JqGrid未从JSON加载数据,java,javascript,jquery,json,jqgrid,Java,Javascript,Jquery,Json,Jqgrid,我有一个JQGrid插件在我的网站上,表加载正常,但没有行可编辑,选择或其他。它正在请求服务器,因为当我查看日志时,我看到了请求及其参数(sidx、_search、rows、sord、nd等) 这是jqgrid代码: $(document).ready(function() { var lastsel; jQuery("#rowed3").jqGrid( { url : CONTEXT_PATH+'/ajax/getPart

我有一个JQGrid插件在我的网站上,表加载正常,但没有行可编辑,选择或其他。它正在请求服务器,因为当我查看日志时,我看到了请求及其参数(sidx、_search、rows、sord、nd等)

这是jqgrid代码:

$(document).ready(function() {
    var lastsel;
    jQuery("#rowed3").jqGrid(
            {
                url : CONTEXT_PATH+'/ajax/getPartesByCategory.do?catid=<s:property value="categoryId" />',
                datatype: 'json',
                colNames : [ 'piezaId', 'descripcion', 'disponible'],
                colModel : [ {
                    name : 'piezaId',
                    index : 'piezaId',
                    align : "right",
                    width : 40
                }, {
                    name : 'descripcion',
                    index : 'descripcion',
                    width : 360,
                    editable : true
                }, {
                    name : 'disponible',
                    index : 'disponible',
                    width : 80,
                    editable : true
                } ],
                rowNum : 20,
                rowList : [ 20, 40, 60, 80 ],
                pager : '#prowed3',
                sortname : 'id',
                viewrecords : true,
                sortorder : "desc",
                onSelectRow : function(id) {
                    if (id && id !== lastsel) {
                        jQuery('#rowed3').jqGrid('restoreRow', lastsel);
                        jQuery('#rowed3').jqGrid('editRow', id, true);
                        lastsel = id;
                    }
                },
                editurl : "server.php",
                caption : "Piezas"
            });
    jQuery("#rowed3").jqGrid('navGrid', "#prowed3", {
        edit : false,
        add : false,
        del : false
    });
})
在服务器端,我使用JAVA6、Struts2和GSon来编写json,但是对于这些ajax调用,我只向响应写入文本/普通内容


有什么帮助吗?

您应该更改从服务器发送的数据格式,或者使用一些
jsonReader
jsonmap
技术(参见示例或和)。最简单的方法是生成可以使用标准
jsonReader
读取的数据(请参阅):


CONTEXT\u PATH
是否与此页面位于同一域中?另外,为什么不使用
application/json
进行响应?是的,CONTEXT\u路径在同一个域中,它位于另一个先加载的.js中(从模板中加载)。。。为什么我没有使用application/json,不知道我刚刚开始编码,也不知道application/json。无论如何,我刚刚实现了一个使用application/json的测试,同样的情况也发生了……json不应该是{“piezaId”:486,…}换句话说,没有方括号:[].@George,json是有效的。它是由两个对象组成的数组。但是,将数组作为最外层类型确实支持某些攻击。请参阅[是否可能对返回JSON对象的URL执行跨站点请求伪造攻击?]()。@Matthew。JQGrid是否期望内容类型为application/json?欢迎!使用
jsonReader
,尤其是使用函数,您可以实际读取JSON数据。我喜欢这个功能。
[{
  "piezaId": 486,
  "disponible": 1,
  "descripcion": "Asiento delantero LH",
  "category": {
    "categoryId": 2,
    "category": "Interior",
    "status": 1,
    "subCategories": []
  }
}, {
  "piezaId": 485,
  "disponible": 1,
  "descripcion": "Asiento delantero RH",
  "category": {
    "categoryId": 2,
    "category": "Interior",
    "status": 1,
    "subCategories": []
  }
}]
{
  "total": "1", 
  "page": "1", 
  "records": "2",
  "rows" : [
    {"id" :"1", "cell":["486","1","Asiento delantero LH"]},
    {"id" :"2", "cell":["485","1","Asiento delantero RH"]},
  ]
}