public class max {
public static void main(String[] args) {
// 创建 ObjectMapper 对象,用于解析 JSON
ObjectMapper objectMapper = new ObjectMapper();
try {
// 读取 JSON 文件并解析为 JsonNode 对象
File jsonFile = new File("E:\\3.json");
JsonNode jsonNode = objectMapper.readTree(jsonFile);
// 假设 JSON 文件中的 JSON 字符串是一个数组,可以通过 JsonNode 的 elements() 方法获取所有元素
int maxAge = Integer.MIN_VALUE;
for (JsonNode element : jsonNode) {
// 获取每个 JSON 字符串的 "age" 字段的值
int age = element.get("Lon").asInt();
// 找到最大值
if (age > maxAge) {
maxAge = age;
}
}
System.out.println("The maximum is: " + maxAge);
} catch (IOException e) {
e.printStackTrace();
}
}
}
查询JSON文件中数据的最值
最新推荐文章于 2024-06-21 17:14:47 发布