小编典典
您必须在运行时检查值的类型。您可以使用Map或使用JsonNode。
Map
JsonParser parser = JsonParserFactory.getJsonParser();
Map map = parser.parseMap(str);
Object filterValue = filter.get("");
if (filterValue instanceof String) {
// str is like "{\"\":\"\"}"
} else if (filterValue instanceof Collection) {
for (Object arrayValue : (Collection) filterValue) {
if (arrayValue instanceof String) {
// str is like "{\"\":[\"\",\"\"]}"
} else if (arrayValue instanceof Map) {
// str is like "{\"\":[{\"operator\":\"eq\",\"value\":\"\"}]}"
}
}
}
JsonNode
ObjectMapper mapper = new ObjectMapper();
JsonNode filter = mapper.readTree(str);
JsonNode filterValue = filter.get("");
if (filterValue.isTextual()) {
// str is like "{\"\":\"\"}"
} else if (filterValue.isArray()) {
for (JsonNode arrayValue : filterValue.elements()) {
if (arrayValue.isTextual()) {
// str is like "{\"\":[\"\",\"\"]}"
} else if (arrayValue.isObject()) {
// str is like "{\"\":[{\"operator\":\"eq\",\"value\":\"\"}]}"
}
}
}
2020-05-30