{"errno":0,"data":{"count":4,"datastreams":[{"datapoints":[{"at":"2021-05-05 09:05:14.971","value":"OK"}],"id":"RET"},{"datapoints":[{"at":"2021-05-06 17:42:27.000","value":36}],"id":"SD"},{"datapoints":[{"at":"2021-05-05 09:05:14.973","value":"0"}],"id":"BEEP"},{"datapoints":[{"at":"2021-05-05 09:05:14.974","value":"28"}],"id":"WD"}]},"error":"succ"}
解决方案:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.28</version>
</dependency>
之后再通过 JsonsRootBean对象 jsonTest 拿到value的值
String value[]=new String[3];
for(int i=1,j=0;i<4;i++){
value[j++] = jsonTest.getData().getDatastreams().get(i).getDatapoints().get(0).getValue();
}
HashMap<String,String > hashMap =new HashMap<>();
hashMap.put("湿度",value[0]);
hashMap.put("报警",value[1]);
hashMap.put("温度",value[2]);
request.getSession().setAttribute("map",hashMap);
DHT dht =new DHT();
dht.setWendu(value[0]);
dht.setBaojing(value[1]);
dht.setShidu(value[2]);
testServeice.save(dht);//保存到数据库
return “test”;
通过 第4部保存的map拿到显示的数据
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1 align="center" ><font color ="red">大棚温湿度检测</font></h1>
</br>
<c:forEach var="entry" items="${map}" >
<h1 align ="center">
${entry.key}
${entry.value}<br/>
</h1>
</c:forEach>
</body>
</html>