使用net.sf.json操作对象与json数据的转换json格式与数据的相互转换
原文地址:https://blog.csdn.net/zz775854904/article/details/81094863
maven使用net.sf.json需要导入的包
<dependency>
<groupId>top.jfunc.json</groupId>
<artifactId>json-jsonlib</artifactId>
<version>1.8.3</version>
</dependency>
springmvc返回json数据 默认编码为iso-8859-1,为避免中文乱码常用解决方案一共两种
1、在@requestMapping注解中添加属性 produces = "text/html; charset=utf-8"
2、在springmvc配置文件中添加
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
<value>application/json;charset=UTF-8</value>
<value>text/plain;charset=UTF-8</value>
<value>application/xml;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
在springmvc中还可以通过配置自动解析后进行操作,但容易出现jar版本问题所以不建议使用