String data = "{json}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = null;
try {
rootNode = objectMapper.readTree(data); //通过将String类型的json数据转化为JsonNode对象
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
JsonNode dataNode = rootNode.get("data");//通过get方法实现对所需信息的提取
JsonNode returnData = dataNode.get(0);//获取第一个数据
System.out.println("returnData:" + returnData);
// 遍历数组元素
if (dataNode.isArray()) {
for (int i = 0; i < dataNode.size(); i++) {
JsonNode arrayElement = dataNode.get(i);
returnData = arrayElement;
System.out.println("数组元素:" + arrayElement);
}
}
标签:JsonNode,get,returnData,arrayElement,json,dataNode,解析,数据
From: https://www.cnblogs.com/IxXi1120/p/18410138