http json串数组作为参数
前端代码
$.ajax({
url: 'http://127.0.0.1:8888/testArray',
data: {title: 'testArray', list: JSON.stringify([23, 56, 19])},
contentType: 'application/x-www-form-urlencoded',
type: 'post',
success(data) {
alert("success")
}
})
后台代码 springboot
@PostMapping("/testArray")
public String testArray(String title, String list){
JSONArray arr = JSON.parseArray(list);
System.err.println(title);
System.err.println(arr.get(0));
System.err.println(arr.get(1));
System.err.println(arr.get(2));
return "success";
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/95da067c2160652ee5a67bfe1ba15a66.png)
依赖 pom.xml
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
</dependency>
题外话 fastjson 小于 1.2.47 存在安全隐患