在读取文件之前,设置文件的编码格式为UTF-8。举例来说:
String filePath = "path/to/file.json";
byte[] contentBytes = Files.readAllBytes(Paths.get(filePath));
String content = new String(contentBytes, StandardCharsets.UTF_8); // 将文件内容按UTF-8编码转为字符串
ObjectMapper objectMapper = new ObjectMapper();
JsonNode tree = objectMapper.readTree(content);
上一篇:编码问题导致字符串差异