标签:pre ret exception ntb key 根据 stack array try
List<JSONObject> jsonValue=new ArrayList<JSONObject>();
JSONArray sortJsonarr=new JSONArray();
for (int i = 0; i < jsonArray.length(); i++) {
try {
jsonValue.add(jsonArray.getJSONObject(i));
} catch (JSONException e) {
e.printStackTrace();
}
}
Collections.sort(jsonValue,new Comparator<JSONObject>() {
private static final String key="id";
public int compare(JSONObject a, JSONObject b) {
Integer valA = 0;
Integer valB = 0;
try {
valA = a.getInt(key);
valB = b.getInt(key);
} catch (JSONException e) {
e.printStackTrace();
}
return valA.compareTo(valB);
}
});
public JSONArray getAllServerType(int uid){ String url = ""; JSONArray jsonArray = this.giantBaseDaoInterface.getJsonObjectByUrl(url); JSONObject json =new JSONObject(); try { json.put("id", "-1"); json.put("text", "全部"); } catch (Exception e) { e.printStackTrace(); } jsonArray.put(json); //排序 List<JSONObject> jsonValue=new ArrayList<JSONObject>(); JSONArray sortJsonarr=new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { try { jsonValue.add(jsonArray.getJSONObject(i)); } catch (JSONException e) { e.printStackTrace(); } } Collections.sort(jsonValue,new Comparator<JSONObject>() { private static final String key="id"; public int compare(JSONObject a, JSONObject b) { Integer valA = 0; Integer valB = 0; try { valA = a.getInt(key); valB = b.getInt(key); } catch (JSONException e) { e.printStackTrace(); } return valA.compareTo(valB); } }); for(int i=0;i<jsonArray.length();i++){ sortJsonarr.put(jsonValue.get(i)); } return sortJsonarr; }
标签:pre ret exception ntb key 根据 stack array try
原文地址:https://www.cnblogs.com/raitorei/p/10550586.html