Jackson解析json文件
程序员文章站
2024-01-12 16:13:10
...
1、ObjectMapper mapper=new ObjectMapper();
2、JsonNode node = mapper.readTree(areaData);
JsonNode lastnode=node.get("result").get("1584548").get("result").get(0).get("shops");
List<WetOrFireCheckVo> list = new ArrayList<WetOrFireCheckVo>();
try {
String areaData = IOUtils.toString(wetOrFireJson.getInputStream(), Charset.forName("UTF-8"));
ObjectMapper mapper=new ObjectMapper();
JsonNode node = mapper.readTree(areaData);
JsonNode wetOrFile = null;
if (Objects.equal(1, wetOrFire)) {
wetOrFile = node.get("wetCheck");
}
if (Objects.equal(2, wetOrFire)) {
wetOrFile = node.get("fireCheck");
}
if (wetOrFile != null && wetOrFile.size() > 0) {
WetOrFireCheckVo wetOrFireCheckVo = null;
for (int i = 0; i < wetOrFile.size(); i++) {
JsonNode jsonNode = wetOrFile.get(i);
wetOrFireCheckVo.setDescribeInfo(jsonNode.get("describeInfo").asText());
wetOrFireCheckVo.setDetail(jsonNode.get("detail").asText());
wetOrFireCheckVo.setHappenTime(jsonNode.get("happenTime").asText());
wetOrFireCheckVo.setId(jsonNode.get("id").asInt());
wetOrFireCheckVo.setModelName(jsonNode.get("modelName").asText());
wetOrFireCheckVo.setModelPath(jsonNode.get("modelPath").asText());
list.add(wetOrFireCheckVo);
}
}
} catch (IOException e) {
e.printStackTrace();
}
上一篇: python中的json模块
下一篇: vs code 常用插件