JSONArray.toJSONString json乱码

前提:配置文件已经配置了:

 <mvc:annotation-driven>
        <!-- 处理请求返回json字符串的中文乱码问题 -->
        <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>    

JSONArray.toJSONString 如果用ajax请求,不会中文乱码;如果在浏览器直接输入地址来请求,结果中文就会出现乱码

所以尽量用 JSON.toJSONString,适用于一切对象转为json字符串

猜你喜欢

转载自www.cnblogs.com/zjfblog/p/10683578.html
今日推荐