调用第三方接口返回json解析
java 代码:
// 请求及返回
Object responses = HttpClientUtils.doPost(XXX请求第三方地址, 接口参数);
// 将返回结果转json JSONObject
JSONObject json = JSON.parseObject(responses.toString());
logger.info("------ letKnowGuard-class json:{}", GsonUtils.gsonString(json));
// 获取对象data数据
JSONObject dataObj = (JSONObject)json.get("data");
// 获取对象data中的data数据 返回的是结果集合
JSONArray dataJson = (JSONArray)dataObj.get("data");
// 处理list集合
for (int j=0;j<dataJson.size();j++){
//业务代码逻辑处理
}
集合排序:
List<Map.Entry<String, Integer>> useList = new ArrayList<>(useMap.entrySet());
Collections.sort(useList, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
// 从大到小排序
return (o2.getValue().compareTo(o1.getValue()));
}
});
List<Map.Entry<String, Integer>> objectList = new ArrayList<>(objectMap.entrySet());
Collections.sort(objectList, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
// 从大到小排序
return (o2.getValue().compareTo(o1.getValue()));
}
});