JSONArray根据某个key进行排序,注意key的类型。
private static JSONArray sortProxyAndCdn(JSONArray bindArrayResult) { System.out.println("排序前:"+bindArrayResult); bindArrayResult.sort(Comparator.comparing(obj -> ((JSONObject) obj).getString("cdn").length()).reversed()); System.out.println("排序后:" + bindArrayResult); return bindArrayResult; }
原文:https://www.cnblogs.com/yongguang1990/p/10249190.html