1: In the use of Ajax request background access to data, the back of the data is garbled, with?? Question mark of garbled, has not encountered before, here records to tidy up, paste out the solution code!
(1): The foreground uses Ajax, has been set to return the result of the JSON format! The AJAX code is not posted!
(2): Background code
/* , produces = "Text/html;charset=utf-8" */ ) @ResponseBody public string Hello (@PathVariable ("UUID") string uuid) { = "" ; // Do something // using JSON to return JSON-formatted data return json.tojsonstring (result);; }
Before adding produces = "Text/html;charset=utf-8" , the returned result has been garbled, very strange, the Project Web. XML also set the encoding format Utf-8, did not find the final reason, but found this solution!
2: If the above method is still unresolved, use the following method:
@ResponseBody Public void Hello (@PathVariable ("UUID") String uuid,httpservletresponse response) { = ""; // Do something // using JSON to return JSON-formatted data New Jsonobject (); Response.setcharacterencoding ("UTF-8"); Response.setcontenttype ("Text/html;charset=utf-8"); Response.getwriter (). Print (Json.tojson (result)); }
Use AJAX request SPRINGMVC return JSON garbled solution