java json

map 转json 
Map<String, Object> map = new HashMap<>();
map.put("key1", "value1");
map.put("key2", 123);
map.put("key3", new Object());
System.out.println(JSON.toJSON(map));

json转对象

ObjectMapper mapper = new ObjectMapper();
GssbCardExtraInfo obj = null;
try {
  obj = mapper.readValue(jsonStr, GssbCardExtraInfo.class);
} catch (JsonProcessingException e) {
  throw new RuntimeException(e);
}

posted @ 2024-06-26 10:49  fxg  阅读(3)  评论(0编辑  收藏  举报