JQuery学习笔记
JSON后台的三种形式
JSCON核心代码
objmapper om = new ojbectMapper();
om.wtireValueAsString();
Student stu1 = new Student("sid", "s001");
Student stu2 = new Student("sname", "lironghao");
ObjectMapper om = new ObjectMapper();
String asString = om.writeValueAsString(stu1);
System.out.println("json对象"+asString);
结果:json对象{“sid”:“sid”,“sname”:“s001”,“set”:[]}
3. JSON数组
List list = new ArrayList();
list.add(stu1);
list.add(stu2);
System.out.println("json数组"+om.writeValueAsString(list));
结果:json数组[{“sid”:“sid”,“sname”:“s001”,“set”:[]},{“sid”:“sname”,“sname”:“lironghao”,“set”:[]}]
List
Map map = new HashMap<>(); map.put("sid", "s001"); map.put("sname", "lironghao"); map.put("stu1", stu1); map.put("stu2", stu2); System.out.println("map的对象"+om.writeValueAsString(map));
List
3map集合的混合模式
List
结果:map的对象{“sname”:“lironghao”,“stu2”:{“sid”:“sname”,“sname”:“lironghao”,“set”:[]},“stu1”:{“sid”:“sid”,“sname”:“s001”,“set”:[]},“sid”:“s001”}
map的数组[{“sname”:“jcak”,“stu2”:{“sid”:“sname”,“sname”:“lironghao”,“set”:[]},“stu1”:{“sid”:“sid”,“sname”:“s001”,“set”:[]},“sid”:“s001”}]
map的混合[{“sname”:“jcak”,“stu2”:{“sid”:“sname”,“sname”:“lironghao”,“set”:[]},“stu1”:{“sid”:“sid”,“sname”:“s001”,“set”:[]},“sid”:“s001”},{“sname”:“jcak”,“stu2”:{“sid”:“sname”,“sname”:“lironghao”,“set”:[]},“stu1”:{“sid”:“sid”,“sname”:“s001”,“set”:[]},“sid”:“s001”}]
$ajax语法
$(function(){
var ctx = $("#ctx").val();//全线命名的隐藏域从界面传过来
$.ajax({
url : ctx+"/json.do",请求url的地址方式为POST
success : function(data){
alert(data);
}
},
dataType : "json" 数据类型
});
});