通过java 获取 {"success":true,"code":"0","message":"Success","data":{"total":85,"list":[{"77":"-2.0","78":"-2.0","subResName":"Aux0/0/1","79":"-2.0","resId":"7362d932b313dcae122647e9e26eb612","subResId":"Aux0/0/1","80":"-2.0","81":"0.0","gatherTime":"1685946600000","82":"0.0","83":"0.0","84":"0.0","85":"0.0","75":"0.0","86":"0.0","76":"0.0","87":"0.0"}],"pageNum":1,"pageSize":10,"size":10,"startRow":1,"endRow":10,"pages":9,"prePage":0,"nextPage":2,"isFirstPage":true,"isLastPage":false,"hasPreviousPage":false,"hasNextPage":true,"navigatePages":8,"navigatepageNums":[1,2,3,4,5,6,7,8],"navigateFirstPage":1,"navigateLastPage":8}} 这个json里面75的值
时间: 2023-07-06 10:35:11 浏览: 155
可以使用 JSON 解析库来解析该 JSON 数据,然后通过键值对的方式获取 75 的值。以下是使用 Jackson 解析库的示例代码:
```java
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
public class JsonParser {
public static void main(String[] args) throws Exception {
String jsonStr = "{\"success\":true,\"code\":\"0\",\"message\":\"Success\",\"data\":{\"total\":85,\"list\":[{\"77\":\"-2.0\",\"78\":\"-2.0\",\"subResName\":\"Aux0/0/1\",\"79\":\"-2.0\",\"resId\":\"7362d932b313dcae122647e9e26eb612\",\"subResId\":\"Aux0/0/1\",\"80\":\"-2.0\",\"81\":\"0.0\",\"gatherTime\":\"1685946600000\",\"82\":\"0.0\",\"83\":\"0.0\",\"84\":\"0.0\",\"85\":\"0.0\",\"75\":\"0.0\",\"86\":\"0.0\",\"76\":\"0.0\",\"87\":\"0.0\"}],\"pageNum\":1,\"pageSize\":10,\"size\":10,\"startRow\":1,\"endRow\":10,\"pages\":9,\"prePage\":0,\"nextPage\":2,\"isFirstPage\":true,\"isLastPage\":false,\"hasPreviousPage\":false,\"hasNextPage\":true,\"navigatePages\":8,\"navigatepageNums\":[1,2,3,4,5,6,7,8],\"navigateFirstPage\":1,\"navigateLastPage\":8}}";
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(jsonStr);
JsonNode dataNode = rootNode.get("data");
JsonNode listNode = dataNode.get("list");
JsonNode itemNode = listNode.get(0); // 取第一个元素
String value75 = itemNode.get("75").asText();
System.out.println(value75);
}
}
```
运行结果为 `0.0`。
阅读全文