当前位置:网站首页>复杂格式的json转递
复杂格式的json转递
2022-08-04 05:33:00 【Jorge666】
jsp中格式
$(function () {
//定义复杂类型Person
var personComplex = {
"id": 1001,
"name":"张三",
"address":{"province":"江苏省","city":"南京市","street":"赛虹桥街道"},
//ajax对象list最外层用[]
"dogs":[{"strain":"哈士奇","color":"黑白"},{"strain":"拉布拉多","color":"黄色"},{"strain":"泰迪","color":"黑色"}],
"dogMap":{
"哈哈":{"strain":"哈士奇","color":"黑白"},
"小黄":{"strain":"拉布拉多","color":"黄色"}
}
}
$("#myBtn3").click(function () {
$.ajax({
"url": "/personComplex",
"data": JSON.stringify(personComplex),
"type": "post",
"contentType": "application/json;charset=utf-8",
"dataType": "json",
"success": function (data) {
console.info(data);
}
})
});
})controller中
@RequestMapping("/personComplex")
@ResponseBody//将java对象转为json格式的数据 @RequestBody主要用来接收前端传递给后端的json字符串中的数据的
public Person sendArray(@RequestBody Person person){
//打印传过来的person的信息
System.out.println(person.getId()+"----"+person.getName());
System.out.println(person.getAddress().getProvince()+"\t"+person.getAddress().getCity()+"\t"+
person.getAddress().getStreet());
System.out.println(person.getDogs().get(1).toString());
System.out.println(person.getDogMap().get("小黄").toString());
//修改哈士奇的颜色
person.getDogs().get(1).setColor("暗金色");
//修改人的名字
person.setName("程东升");
return person;
}边栏推荐
猜你喜欢
随机推荐
给想要转行渗透测试人的忠告
Vmmem 进程(WSL2)消耗内存巨大
Unity Day03
LeetCode_Nov_2nd_Week
关于网络安全行业你知道多少?
file editor
Shell脚本执行的三种方式
动态内存管理-C语言
华为鲲鹏arm服务器下使用webrtc和boost踩坑记--编译篇
淘宝分布式文件系统存储(二)
以太网 ARP
webrtc技术名词和关键技术要点:SVC,REMB,SVC...
Design and implementation of legal aid platform based on asp.net (with project link)
Miscellaneous [development] [VS Code] remote - SSD retry failed
网络安全行业是蓝景吗?
基于语音识别的QT设计的csgo互动类视频游戏
clssloader与双亲委派
[Development miscellaneous][Debug]debug into kernel
通过socks5代理下载webrtc源码错误:curl: (7) Can't complete SOCKS5 connection xx.xx.xx.xx
LeetCode_Dec_2nd_Week









