map.put("name", "lisi");
ObjectMapper mapper= new ObjectMapper();
String str = mapper.writeValueAsString(map);
JSONObject obj = JSONObject.fromObject(str);
本文介绍了一种将Java对象转换为JSON字符串的方法,通过使用Map和ObjectMapper,再将其转换为JSON格式,最后利用JSONObject进行解析。
map.put("name", "lisi");
ObjectMapper mapper= new ObjectMapper();
String str = mapper.writeValueAsString(map);
JSONObject obj = JSONObject.fromObject(str);

被折叠的 条评论
为什么被折叠?
