spring rest 接收json数据
2013-05-16 15:28
288 查看
@RequestMapping("/appservices/appinfo") @Controller public class AppInfoWebService { @RequestMapping(value = "/get", method = RequestMethod.POST) @ResponseBody public AccountBean show(@RequestBody String appId) { System.out.println(appId); ObjectMapper mapper = new ObjectMapper(); try { Map<String, Object> account = mapper.readValue(appId, Map.class); for(Map.Entry<String, Object> entry : account.entrySet()) { Object obj = entry.getValue(); if(obj instanceof String) { System.out.println(obj.toString()); } else if(obj instanceof List) { List<Integer> value = (List)obj; for(Integer sub : value) { System.out.println("sub:::" + sub); } } System.out.println(entry.getKey() + ":" + entry.getValue()); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } // for (Map.Entry<String, Object> entry : appId.entrySet()) { // System.out.println(entry.getKey() + ":" + entry.getValue()); // } AccountBean bean = new AccountBean(); bean.setAddress("china-Guangzhou"); bean.setEmail("hoojo_@126.com"); bean.setId(1); bean.setName("hoojo"); Birthday birthday = new Birthday(); birthday.setBirthday("1983.08.01"); bean.setBirthday(birthday); return bean; } }
上传示例:
{"address":"bbb","list":[111,222,333]}
如果发现415错误,请增加头部
"Content-Type", "application/json; charset=utf-8"
相关文章推荐
- 如何在Django中接收JSON格式的数据
- 删除文件及文件夹,接收安卓json数据,select框函数封装
- 客户端POST发送json数据给服务端,客户端端接收服务器端json数据响应
- 用springMVC构建restful程序,接收以及返回json数据格式
- PHP接收json并将接收数据插入数据库
- golang revel下免声明对象动态接收json post 数据
- ThinkPHP中使用ajax接收json数据的方法
- post接收json数据
- MVC接收前台json数据,反序列化为指定实体对象
- android发送/接收json数据 --很给力
- 在PHP中怎么接收post过来的JSON数据(可以是接口推送过来的数据)
- HttpClient和HttpUrlConnection实现post发送和接收json数据
- php接收json格式数据(text/xml)
- php服务端接收post的json数据
- 初涉Ajax,以post或get方法发送数据,以json或xml形式接收服务器返回的请求
- 可以再页面这样写,保证接收后台报错的json数据
- 使用fastjson与SpringMVC实现自定义HttpMessageConverter接收和获取JSON格式的数据
- 关于java接收前台$.ajax格式为多维json数组数据为null的原因及解决方法
- .NET后台接收Json数据,序列化到指定实体类