0

我正在使用 DataTable 1.7.5 和 JQuery-1.7.1.min.js 并得到一个 JSON 解析错误。在浏览几个在线论坛时,建议升级 JQuery-1.5.1.min.js 的验证器插件,但没有关于 JQuery-1.7.1.min.js 的验证器。是否有人对此问题有任何建议?

Table HTML:
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" >
                    <thead>
                        <tr>
                            <th>#</th>                              
                            <th></th>
                            <th>Name</th>
                            <th>Shpr</th>
                            <th>Org</th>
                            <th>Cne</th>
                            <th>Dest</th>
                            <th>Dep Dt</th> 
                            <th>LR No</th>
                            <th>Asset No</th>
                            <th>Curr Dt</th>
                            <th>Spd km/h</th>
                            <th>Waypoint1</th>
                            <th>Waypoint2</th>
                            <th>SDA</th>
                            <th>DETA</th>   
                            <th>AMC</th>                                                        
                        </tr>
                    </thead>
                    <tbody>

                    </tbody>
</table>

Javascript:

var oTable = $('#example').dataTable({

                "aLengthMenu" : [[-1, 10, 25, 50, 100], ["All", 10, 25, 50, 100]],
                "iDisplayLength" : -1,
                "bProcessing": true,
                "bJQueryUI": true,
                "bAutoWidth": false,
                //"sScrollY": "300px",
                "sPaginationType": "full_numbers",
                "sAjaxSource": "ReportAction.do?process=home",
                "bDeferRender":true,
                "sDom": 'T<"clear"><"H"lfr>t<"F"ip>',
                "oTableTools": {
                    "sSwfPath": "<%=localrequestedURL %>media/swf/copy_csv_xls_pdf.swf"
                }       
            });

JSON数据:

result = session.createSQLQuery(sql_homepage).list();
String final_data = gson.toJson(result);
final_message = "{\"aaData\":"+final_data+"}";

1. 变量 sql_homepage 指的是对数据库的选择查询。2. 变量 final_message 被传递给将数据传递给 JSP 的动作类。

4

1 回答 1

0

我遇到了同样的问题,它来自一个保存到数据库中的隐形字符。最好使用 json 验证器来查看您的错误在哪里。我用了这个:http ://www.freeformatter.com/json-validator.html和这个http://jsonformatter.curiousconcept.com/

datatables 对它将解析的 JSON 非常挑剔。我必须 100% 完美,我最终需要创建一个 php 函数来生成 JSON 对象字符串,而不仅仅是使用 php 函数 json_encode

于 2014-01-27T07:15:53.470 回答