@Test
void contextLoads() throws Exception {
String fileName = "1.json";
String currentFilePath = new Object(){}.getClass().getEnclosingClass().getResource("").getPath()+"/"+fileName;
String substring = currentFilePath.replaceAll("target/test-classes", "src/test/java").substring(1);
// 使用相对路径指定JSON文件,假设在同一目录下
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(new File(substring));
System.out.println("jsonNode = " + jsonNode);
}
java代码读取统计目录下的json文件并转换成json对象
最新推荐文章于 2024-05-10 09:14:14 发布