一、map与each的使用
1 2 3 4jquerydemo 5 7 17 18 19 20 21 22 23 24
二、ajax
$(function () { $.ajax({ type: "GET", url: "some", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg.name ); alert( "Data Saved: " + msg.location ); } }); });
$(function () { $.ajax({ type: "POST", url: "some", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg.name ); alert( "Data Saved: " + msg.location ); } }); });
@RequestMapping("/some") @ResponseBody public MapgetSome(String name, String location) throws IOException { System.out.println("GET"); Map map = new HashMap (); map.put("name",name); map.put("location",location); return map; } @RequestMapping(value = "/some",method = RequestMethod.POST) @ResponseBody public Map postSome(String name, String location) throws IOException { System.out.println("POST"); Map map = new HashMap (); map.put("name",name); map.put("location",location); return map; }
三、JSON.parse()和JSON.stringify()区别
JSON.parse()【从一个字符串中解析出json对象】例子://定义一个字符串var data='{"name":"goatling"}'//解析对象 就是将json字符串转换为对象JSON.parse(data)结果是:name:"goatling"JSON.stringify()【从一个对象中解析出字符串】 说白了就是将json对象转换为字符串var data={name:'goatling'}JSON.stringify(data)结果是:'{"name":"goatling"}'