@Override
public HashMap<String, String> getDeviceTreeChildrenMap(Map<String, String> map) {
String code = map.get("code");
JSONObject jsonObject = new JSONObject();
jsonObject.put("root", code);
String json = HttpClientUtil.sendPostJson(DeviceTools.DEVICE_API_BASE_URL + "/basicconf/getFacilityTreeWithFilterAlt", jsonObject.toString());
JSONArray jsonArray = JSON.parseArray(json);
JSONArray result = new JSONArray();
HashMap<String, String> dataMap = new HashMap<>(16);
JSONArray resultNode = findJsonNode(jsonArray, result);
if (resultNode != null) {
if (resultNode.size() > 0) {
for (int i = 0; i < resultNode.size(); i++) {
JSONObject job = resultNode.getJSONObject(i);
dataMap.put(job.get("id").toString(),job.get("label").toString());
}
}
}
return dataMap;
}
private JSONArray findJsonNode(JSONArray jsonArray, JSONArray result) {
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject job = jsonArray.getJSONObject(i);
JSONArray children = (JSONArray) job.get("children");
if (children != null) {
if (children.size() > 0) {
findJsonNode(children, result);
}
} else {
result.add(job);
}
}
return result.size() > 0 ? result : null;
}
09-15
5026
05-19
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交