0

我在 JSP 中编写了代码,并使用 JSON 对象在 JqGrid 中显示数据。

我知道我的 JSON 对象有数据(我已经记录了它的内容),但它没有显示在 JqGrid 中。当我将 JSON 数据复制到 JSON 字符串中时,它会被加载并成功显示在 Jqgrid 中。

这是我的 JSP 代码:

JSONObject responcedata = new JSONObject();   
responcedata.put("total",totalrow);     
responcedata.put("page",cpage);     
responcedata.put("records",rcount);    
Report obj = new Report(); 
responcedata = obj.ReportGrid(responcedatal); 
System.out.println(responcedata); 

这是我的 JSON 对象的内容:

{"total":"21″,"rows":[{"cell":["HS","H","10","5","G","9288"],"id":" 1″},{"cell":["",null,null,null,"G","2099"],"id":"2″},{"cell":["HS","F" ,"3","53","G","86578"],"id":"3″},{"cell":["HS","F","7","26"," G","8268"],"id":"4″},{"cell":["HS","F","8","54","G","221"],"id ":"5″},{"cell":["HS","F","5","77","G","1020"],"id":"6″},{"cell ":["HS","H","14","14","G","73334"],"id":"7″},{"cell":["HS","C","21","1 ","G&B","1512"],"id":"8″},{"cell":["HS","F","2","105","G","4960"] ,"id":"9″},{"cell":["HS","F","4","21","G","86889"],"id":"10″}] “记录”:11}G","4960"],"id":"9″},{"cell":["HS","F","4","21","G","86889"],"id ":"10″}],"记录":11}G","4960"],"id":"9″},{"cell":["HS","F","4","21","G","86889"],"id ":"10″}],"记录":11}

我使用了这个 JSON 字符串,而 JqGrid 正在显示数据。当我使用 JSON 对象时,变量responcedata(在上面的代码中)只显示加载,但从不显示数据。

4

2 回答 2

0
    function callMe() {
    $.ajax({
        type : "POST",
        url : "action name",
        data : {}
    }).done(function(data) {

                // dat has list there is 5 column (id,fname,lname,username,password)

        var len = data.length;

        var t="";
        for (var i=0; i<len; ++i) {
                var id =  data[i].id;
                var fname =  data[i].fname;
                var lname =  data[i].lname;
                var username =  data[i].username;
                var password =  data[i].password;                      
                t+="<tr><td>"+id+"</td><td>"+fname+"</td><td>"+lname+"</td><td>"+username+"</td><td>"+password+"</td></tr>"
         } 

         print(t,data);
    });
}

function print(t, data) {
    document.getElementById("welcometext").innerHTML = t;   
}

在 html 中:

 <table id="welcometext" border="1">

    </table>
于 2013-02-19T09:19:58.717 回答
0

我在包含 json 数据的 Jsp 文件中包含了另一个 Jsp。我删除了包含行。现在它工作正常。

于 2013-02-19T12:44:44.443 回答