The Springmvc used transmits a json to the front desk in the controller layer. The background display is no problem, and Chinese is displayed normally and reaches the front desk. This article mainly introduces the solution to the problem of question marks and garbled characters in Chinese when using ajax to transfer json to the front desk. Friends in need can refer to it. I hope it can help everyone.
The Chinese becomes a question mark.
Later I discovered that because @ResponseBody is used to return json in the controller, and the implementation class of @ResponseBody in the spring source code found that its default encoding is iso-8859-1, and the encoding used by the project is utf-8 , so there will be garbled characters when transmitting Chinese.
Here I used annotations to solve the problem:
@RequestMapping(value="/echarts.do", produces = "application/json; charset=utf-8")
This method is more suitable for the new version of spring. The version of this project:
<spring.version>4.1.4.RELEASE</spring.version>
The above is the solution introduced by the editor to the problem of garbled question marks in Chinese when passing json to the front desk using ajax. I hope it will be helpful to everyone.
Related recommendations:
How to transfer json objects between html?
PHP transfers Json data between different pages Sample Code_PHP Tutorial
JSON Advanced Part 2: Passing JSON Data in AJAX Way_PHP Tutorial
The above is the detailed content of How to solve the problem of garbled question marks when passing json to the front desk using ajax?. For more information, please follow other related articles on the PHP Chinese website!