我收到了"DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error"错误信息。我使用Java和dataTables在代码中进行输出,输出格式为JSON,但是客户端打印时无法识别。http://jsonlint.com/ 中验证的JSON对象格式正确。我不确定是什么原因导致了这个错误。
数据如下:
{"iTotalRecords":5,"sEcho":"1","aaData":[["V2993ASFKH230943","Honda","Accord"],["V2993A39SNF30943","Honda","CRV"],["V4833A39SNF30943","Acura","TSX"],["V4833RE9SNF30943","Acura","TL"],["V9383RE9SNF30943","Acura","MDX"]],"iTotalDisplayRecords":5}
非常感谢帮助。
谢谢!
数据如下:
{"iTotalRecords":5,"sEcho":"1","aaData":[["V2993ASFKH230943","Honda","Accord"],["V2993A39SNF30943","Honda","CRV"],["V4833A39SNF30943","Acura","TSX"],["V4833RE9SNF30943","Acura","TL"],["V9383RE9SNF30943","Acura","MDX"]],"iTotalDisplayRecords":5}
非常感谢帮助。
谢谢!
try {
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("sEcho", sEcho);
jsonResponse.put("iTotalRecords", iTotalRecords);
jsonResponse.put("iTotalDisplayRecords", iTotalDisplayRecords);
while (itr.hasNext()) {
Map rs = (Map) itr.next();
FleetEquipment eqpmt = new FleetEquipment();
eqpmt.setVinNumber((String) rs.get("VIN_ID"));
eqpmt.setMake((String) rs.get("MAKE"));
eqpmt.setModel((String) rs.get("MODEL"));
JSONArray row = new JSONArray();
row.put(eqpmt.getVinNumber()).put(eqpmt.getMake())
.put(eqpmt.getModel());
data.put(row);
}
jsonResponse.put("aaData", data);
response.setContentType("application/json");
response.getWriter().print(jsonResponse.toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
response.setContentType("text/html");
response.getWriter().print(e.getMessage());
}
编辑 1
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<portlet:defineObjects/>
<portlet:resourceURL var="listURL" id="list" escapeXml="false"/>
<script type="text/javascript">
$(document).ready(function () {
$('#listTable').dataTable({
"bServerSide": true,
"sAjaxSource": "<%=listURL.toString()%>",
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": true
});
});
</script></head>
<body>
<table id="listTable">
<thead>
<tr>
<th>VIN ID</th>
<th>MAKE</th>
<th>MODEL</th>
<th>MODEL1</th>
<th>Model2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>