首页 > 技术文章 > java json数据返回值中文乱码 出现???

xkoko 2019-02-27 14:33 原文

 

后台方法返回值出现乱码

 

JSONObject json=new JSONObject();

json.put("totals1",map);

 return json.toJSONString();

 

如图

 

 解决办法:在Spring-MVC.xml配置文件添加以下配置,然后直接返回要生成Json串的对象 

<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean id="stringHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes" value="application/json;charset=UTF-8"/>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>

 

推荐阅读