欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Jackson解析json文件

程序员文章站 2024-01-12 16:13:10
...
1、ObjectMapper mapper=new ObjectMapper();
2、JsonNode node = mapper.readTree(areaData);

Jackson解析json文件

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();
		}

 

相关标签: json