我正在尝试将一些 JSON 动态解析为 Map。以下内容适用于简单的 JSON
String easyString = "{\"name\":\"mkyong\", \"age\":\"29\"}";
Map<String,String> map = new HashMap<String,String>();
ObjectMapper mapper = new ObjectMapper();
map = mapper.readValue(easyString,
new TypeReference<HashMap<String,String>>(){});
System.out.println(map);
但是当我尝试使用一些更复杂的带有嵌套信息的 JSON 时失败了。我正在尝试解析来自 json.org 的示例数据
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": [
"GML",
"XML"
]
},
"GlossSee": "markup"
}
}
}
}
}
我收到以下错误
线程“主”com.fasterxml.jackson.databind.JsonMappingException 中的异常:无法从 START_OBJECT 令牌中反序列化 java.lang.String 的实例
有没有办法将复杂的 JSON 数据解析成地图?