Skip to content

Instantly share code, notes, and snippets.

@paxti
Created March 3, 2016 23:45
Show Gist options
  • Save paxti/6fb4da4b8779f810ab6b to your computer and use it in GitHub Desktop.
Save paxti/6fb4da4b8779f810ab6b to your computer and use it in GitHub Desktop.
Filter JSONArray using attribute of JSONObject
private ArrayList<JSONObject> getFilteredList(JSONArray options){
Map<String, JSONObject> map = new ArrayMap<>();
for (int i = 0; i < options.length(); i++){
try {
JSONObject object = options.getJSONObject(i);
String key = object.getString("Order_Type__c") + object.getString("Opp_SFID__c");
if (!map.containsKey(key)){
map.put(key, object);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return new ArrayList<JSONObject>(map.values());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment