springboot
springboot默认自带json解析框架,默认使用jackson
SpringMVC
需要的jar包:
Controller:
@RequestMapping("/testJson")
public String testJson5(@RequestBody List<Person> persons) {
System.out.println(persons);
return "success";
}
使用Maven管理jar包时:
一、jackjson maven
<jackjson.version>2.8.8</jackjson.version> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>${jackjson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>${jackjson.version}</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackjson.version}</version> </dependency>
二、fastjson maven
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.32</version> </dependency>
Ajax
function fun(){
$.ajax({
url:'/testAjax.action',
data:"{'name':'xujie','age':'25'}",
type:'POST',
dataType:'json', //告诉服务器,我要接收的是json格式数据
contentType:'application/json' //告诉服务器我发送的是json格式数据
})
}