I am trying to return a JSON string upon a AJAX callback.
I have kept my code as simple as I can, however I find that the callback is always error, and the error message is:
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
I use firebug to check the JSON response, and there is a strange character at the start of the response string (the one with red square in the attached picture)
And here is my Servlet:
response.setContentType("application/json;charset=UTF-8");
final JsonObject jsonResponse = new JsonObject();
.
.
.
.
jsonResponse.addProperty("result", "success");
final String jsonResponseString = jsonResponse.to![enter image description here][2]String();
response.getWriter().write(jsonResponseString);
Could anyone give me some help?
I feel like I am one step behind the answer, but I just cannot get it.
Thanks~