在我的应用程序中,我将 JSON 内容作为 InputStream。取决于我想要执行不同操作的单个 JSONObject 还是 JSONArray。
如果它是单个对象或对象数组,我如何区分,使用杰克逊?
//欢呼
解决方案:
使用 JsonNote.isArray():
JsonNode rootNode = mapper.readValue(contentStream, JsonNode.class);
List<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
if(rootNode.isArray()){
// do something with the array
} else {
// do something else with the object
}