map转json,json转对象

来源:互联网 发布:管家软件哪个好 编辑:程序博客网 时间:2024/05/21 10:06

map转json字符串

Map<String, String> map = new HashedMap();

map.put("layers", “cite:aa”);
map.put("crs", "EPSG:4326"); 
map.bbox("bbox","111,222,222,3333");

ObjectMapper mapper = new ObjectMapper();
String str2 = "";
try {
str2 = mapper.writeValueAsString(map);
} catch (IOException e) {
System.out.println("序列化JSON数据失败");
e.printStackTrace();
}

json字符串转对像

JSONObject obj=new  JSONObject(); 

obj.put("name","张三");

obj.put("age",18);

Student s=(Student)JSONObject.toBean(jsonObj,Student.class);

注意:Student对象中必须有name和age属性

原创粉丝点击