JSON formatting error

JSON formatting error

peterwkcpeterwkc Posts: 21Questions: 0Answers: 0
edited October 2012 in General
Hello to all of you, I using JQuery Data Table to display data but i getting JSON formatting error when post data back from server to client.

JSP
[code]


$(document).ready(function()
{
$("#ticketList").dataTable({

"bProcessing" : true, // Enable processing indicator
"bServerSide" : true, // Configure data option - server or client
// Send XHR request to server
"sServerMethod": "POST", // GET or POST
"bSort" : true, // Enable sorting
"bFilter" : false,
"bAutoWidth" : true,
"sPaginationType" : "full_numbers", // Paginate Type -> two_button (Previous && Next)
// -> full_numbers (First, Previous, 1, 2, Next, Last)
"bLengthChange" : true,
"iDisplayLength" : 10,
"sAjaxSource" : "${context}/app.view?tn=Ticket.SearchTicket",
// Override $.getJson() get data from server
/*"fnServerData": function(sSource, aoData, fnCallback) {
$.ajax({ "dataType": 'json',
"type": "GET", // GET or POST to server for getting data
"url": sSource,
"data": aoData,
"success": fnCallback,
"error": function(jqXHR, textStatus, errorThrown) {
console.log(txtStatus, errorThrown); // use alert() if you prefer
}
});
}, */

"aoColumns": [
//mData mDataProp
{"mData": "id"},
{"mData": "category"},
{"mDataP": "status"},
{"mData": "assignee"},
{"mData": "urgency"},
{"mData": "action"}
]
});
});



Search Ticket





Ticket Id:




Category:

Account
Invoice
Rates
No category




Urgency:

High
Medium
Low
No urgency




Status:

Unassigned
In Progress
Solved
No Status







Search Ticket









<!-- Show

2
4
6

entries
-->

<!-- -->



Ticket ID
Category
Urgency
Status
Assignee
Action




Loading data from server



<!-- -->






[/code]

Servlet
[code]
@Override
public TaskResponse execute(HttpServletRequest request,
HttpServletResponse response) throws WebTaskException {

String sEcho = null;
String sSearch = null;

HttpSession session = request.getSession();

if (session == null) {
throw new WebTaskException("Unauthorized Access");
}

sEcho = request.getParameter("sEcho");
sSearch = request.getParameter("sSearch");
// Get page number -> Pagination -> XHR request
if (sEcho != null) {
Integer id = null;
String categoryStr = request.getParameter("category");
String urgencyStr = request.getParameter("urgency");
String statusStr = request.getParameter("status");
int fetchRowSize = 100;
int currentRow = 0;

if (request.getParameter("iDisplayLength") != null) {
fetchRowSize = Integer.parseInt(request.getParameter("iDisplayLength"));
logger.log(Level.INFO, "Fetch Row Size " + fetchRowSize);
}

if (request.getParameter("iDisplayStart") != null) {
currentRow = Integer.parseInt(request.getParameter("iDisplayStart"));
logger.log(Level.INFO, "Current Row " + currentRow);
}

Ticket ticket = new Ticket();
List ticketList = new ArrayList();

if (request.getParameter("id") != null && request.getParameter("id") != "") {
id = Integer.parseInt(request.getParameter("id"));
ticket.setId(id.intValue());
} else {
ticket.setId(-1);
}

if (this.category.get(categoryStr) != null) {
ticket.setCategory(this.category.get(categoryStr).intValue());
} else {
ticket.setCategory(-1);
}

if (this.urgency.get(urgencyStr) != null) {
ticket.setUrgency(this.urgency.get(urgencyStr).intValue());
} else {
ticket.setUrgency(-1);
}

if (this.status.get(statusStr) != null) {
ticket.setStatus(this.status.get(statusStr).intValue());
} else {
ticket.setStatus(-1);
}

ticketList = dao.findTicket(ticket, fetchRowSize, currentRow);

JSONObject jsonObject = convertObject(ticketList);
logger.log(Level.INFO, "Json String " + jsonObject.toString());

// taskResponse.setResponseType(ResponseType.JSON);
taskResponse.setResponseText(jsonObject.toString());

logger.log(Level.INFO, "searchTicket POST XHR Request called");

/* MySql Pagination Test */
/*ticketList = dao.getAllTickets(id);
for (Ticket t: ticketList) {
logger.log(Level.INFO, String.valueOf(t.getId()));
}*/

} else {
request.setAttribute("tableView", "tableView");
}
logger.log(Level.INFO, "searchTicket GET called" + String.valueOf(++callTime));
//taskResponse.addForwardTask(VBossProperties.getInstance(), "admin.ViewDefinePrivilege");
return taskResponse;
}
[/code]
I had tried debug with firebug which found nothing and check the Json string using JSONINT and it say it is a valid json. What is the reason that cause this error? Please help. Thanks.

Replies

  • allanallan Posts: 63,532Questions: 1Answers: 10,475 Site admin
    Please link use to the page or use the DataTables debugger can give us the debug code.

    Allan
This discussion has been closed.