//直接使用java的Collections對集合進行排序,這裏是通過通話的次數call_cnt這個json的key來進行由大到小降序排序
List<Map> list= (List<Map>) JSONObject.parseObject(value.get("report_data").toString()).get("contact_list");
Collections.sort(list, new Comparator<Map>() {
@Override
public int compare(Map o1, Map o2) {
if(o1 instanceof Map && o2 instanceof Map) {
Map e1 = (Map) o1;
Map e2 = (Map) o2;
//需要升序的話就Integer.parseInt(e1.get("call_cnt").toString())-Integer.parseInt(e2.get("call_cnt").toString());
return Integer.parseInt(e2.get("call_cnt").toString())-Integer.parseInt(e1.get("call_cnt").toString()) ;
}
throw new ClassCastException("轉換成int類型失敗");
}
});