我需要在这个arrayNode中得到这个值(以防万一,我知道它只会是数组中的一个值--请不要问我为什么,这就是我接收它的方式):
"data": {
"services": [
"ISP3100008972@some.com"
]
}我正在运行这部分代码:
ArrayNode arrNode = (ArrayNode) new ObjectMapper().readTree(resBody).path("data").get("services");
if (arrNode.isArray()) {
for (final JsonNode objNode : arrNode) {
serviceId = objNode.get(0).textValue();
log.info("serviceId: " + serviceId + " is available");
}
}我在这一行中得到一个java.lang.NullPointerException: null : serviceId = objNode.get(0).textValue();
拜托,谁能看看这个吗?非常感谢。
发布于 2020-03-19 05:21:09
您正在调用objNode.get(0),如果objNode是数组节点,它将检索数组的第一个值--但它不是,而是数组中的节点。如果节点不是数组,JsonNode.get(int)将返回null。
你只需要:
serviceId = objNode.textValue();https://stackoverflow.com/questions/60751270
复制相似问题