com.fasterxml.jackson完成json转map
程序员文章站
2024-02-04 13:36:10
...
com.fasterxml.jackson完成json转map
在开发时有时候需要将接收到的json字符串转成map
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
try{
String jsonStr = "{\"errcode\":40163,\"errmsg\":\"code been used, hints: [ req_id: .bYjNa04342034 ]\"}";
ObjectMapper objectMapper = new ObjectMapper();
HashMap<String,Object> map = objectMapper.readValue(jsonStr,HashMap.class);
}catch(Exception e){
e.printStackTrace();
}