我无法打印orderNumber的值。能够打印有效载荷的值。
ObjectMapper mapper = new ObjectMapper();
File jsonFile = new File("abc.json");
HashMap<String, HashMap<String, String>> jsonmaps = mapper.readValue(
jsonFile,
new TypeReference<HashMap<String, String>>() {});
System.out.println(jsonmaps.size());
System.out.println(jsonmaps.get("payload"));
HashMap<String,String> map = (HashMap<String,String>)jsonmaps.get("payload");
System.out.println(map.get("orderNumber"));
Json文件:
{"payload":{"orderNumber":"1","name":"abc"}}
我遇到错误。
Exception in thread "main" java.lang.ClassCastException: java.lang.String cannot be cast to java.util.HashMap