版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_30060779/article/details/85229874
1、从JsonObject中获取JsonArray、(从获取的复杂数据中取出其中的List)
@Override
public JSONArray getEnpList(Integer pageNumber, Integer pageSize) {
MultiValueMap<String, String> requestEntity = getBaseMultiValueMap(CommonPara.POST, "open.shopweb.departments.getDeptListByPage");
requestEntity.add("pageNumber", String.valueOf(pageNumber));
requestEntity.add("pageSize", String.valueOf(pageSize));
setSig(requestEntity);
JSONObject data = doRestTemplate(requestEntity);
JSONArray records = data.getJSONArray("records");
return records;
}
/**
* 执行调用
*
* @param requestEntity
* @return
*/
private JSONObject doRestTemplate(MultiValueMap<String, String> requestEntity) {
HttpEntity<Object> httpEntity = new HttpEntity<>(requestEntity, getHttpHeaders());
ResponseEntity<JSONObject> response = restTemplate.exchange(URL, HttpMethod.POST, httpEntity, JSONObject.class);
JSONObject responseData = response.getBody();
JSONObject data = responseData.getJSONObject("data");
return data;
}
2、从JsonArrayList中获取第一条状态正常的数据,从中获取数据
/**
* 获取视频资料
* @param enpPoint
* @return
*/
@RequestMapping("/getVideo")
public ReturnEntity getVideo(EnpPoint enpPoint) {
//获取设备列表
ReturnEntity returnEntity = new ReturnEntity();
List<EnpVideo> enpVideos = enpVideoService.getDeviceByEnpId(enpPoint.getEnpId());
if(CollectionUtils.isNotEmpty(enpVideos)){
List<EnpVideo> enpVideos1 = new ArrayList<>();
String onLineVideoId = "";
JSONArray videoDeviceList = enpVideoService.getVideoDeviceList(enpVideos.get(0).getStoreId());
if(videoDeviceList != null && videoDeviceList.size()>0){
JSONObject videoJson = videoDeviceList.getJSONObject(0);
JSONArray devices = videoJson.getJSONArray("devices");
for (int j = 0; j < devices.size(); j++) {
JSONObject device = devices.getJSONObject(j);
if("1".equals(device.getString("online"))){
onLineVideoId += device.getString("id");
}
}
}
for(EnpVideo video: enpVideos){
if(onLineVideoId.indexOf(video.getDeviceId())>-1){
enpVideos1.add(video);
}
}
if(enpVideos1.size()>0) {
EnpVideo enpVideo = enpVideos1.get(0);
JSONObject jsonObject = enpVideoService.getVideoList(String.valueOf(enpVideo.getDeviceId()));
jsonObject.put("deviceList", enpVideos1);
jsonObject.put("isControl", enpVideo.getIsControl());
returnEntity.setReturnData(jsonObject);
}else{
returnEntity.setErrorEntity("无可用设备!");
}
}else{
returnEntity.setErrorEntity("无可用设备!");
}
return returnEntity;
}