Solution to the garbled json Chinese string returned during spring MVC Ajax request, springmvcjson
The 1.org. springframework. http. converter. StringHttpMessageConverter class is a class that processes requests or strings, and the default character set is ISO-8859-1, so garbled characters appear when the returned json contains Chinese characters.
2. the parent class of StringHttpMessageConverter has a List <MediaType> supportedMediaTypes attribute to store the MediaType type that StringHttpMessageConverter supports special processing. If the MediaType type to be processed is not in the supportedMediaTypes List, the default character set is used.
3. Solution: Add the following code to the configuration file:
<! -- Solve the garbled problem when springmvc transmits json values --> <mvc: annotation-driven> <mvc: message-converters> <bean class = "org. springframework. http. converter. stringHttpMessageConverter "> <property name =" supportedMediaTypes "> <list> <value> application/json; charset = UTF-8 </value> </list> </property> </bean> </mvc: message-converters> </mvc: annotation-driven>
4. If you need to process other MediaType types, you can add other value tags to the list tag.
(Java) Chinese garbled characters in json format returned by jsp page ajax
Add
$. Ajax ({
ContentType: "application/json ",});
Springmvc js ajax Chinese garbled Problem
At the beginning of a little look at your problem, probably understand, garbled reasons are probably your server encoding problem, tomcat's default encoding is ISO-8859-1 this encoding, so if you need to change it, tomcat/conf/server. in xml, find Connector and add URIEncoding = "UTF-8" to it. If you don't change it, you have to return it in the action, that is, the receiver decoded with the ISO-8859-1, for example, new String (str. getBytes ("ISO-8859-1"), "UTF-8"); if an interceptor is used, it will be decoded in the interceptor. You can try it! Hope to help you!