二、springmvc 接收不同格式的json字符串
2).格式二:json字符串数组
前台:
test = function () { var test = ["123","qwe","asd"]; jQuery.ajax({ url : cur_url+"/weekly/test", type : 'post', data : JSON.stringify(test), dataType : 'json', contentType:'application/json;charset=utf-8', success : function (data, textStatus) { console.info(data); alert("test success!"); }, error:function(){ alert("test error!"); } }); };
后台接收:
@RequestMapping("/test") @ResponseBody public List<String> test(@RequestBody String[] strs ) { for (String s : strs) { System.out.println(s); } return Arrays.asList(strs); }
3).格式三:json 数字组成的数组
前台发送:
test = function () { var test = [1231,4562,7893]; jQuery.ajax({ url : cur_url+"/weekly/test", type : 'post', data : JSON.stringify(test), dataType : 'json', contentType:'application/json;charset=utf-8', success : function (data, textStatus) { console.info(data); alert("test success!"); }, error:function(){ alert("test error!"); } }); };
后台接收:
@RequestMapping("/test") @ResponseBody public List<Integer> test(@RequestBody Integer[] strs ) { for (Integer s : strs) { System.out.println(s); } return Arrays.asList(strs); }