Skip to content

Instantly share code, notes, and snippets.

@josedlujan
Forked from emmgfx/gist:0f018b5acfa3fd72b3f6
Created February 24, 2016 17:39
Show Gist options
  • Select an option

  • Save josedlujan/b7f34d18075fb987b426 to your computer and use it in GitHub Desktop.

Select an option

Save josedlujan/b7f34d18075fb987b426 to your computer and use it in GitHub Desktop.
Android JSONArray remove before API 19
// Example of use: remove(i, savedProfiles);
public static JSONArray remove(final int idx, final JSONArray from) {
final List<JSONObject> objs = asList(from);
objs.remove(idx);
final JSONArray ja = new JSONArray();
for (final JSONObject obj : objs) {
ja.put(obj);
}
return ja;
}
public static List<JSONObject> asList(final JSONArray ja) {
final int len = ja.length();
final ArrayList<JSONObject> result = new ArrayList<JSONObject>(len);
for (int i = 0; i < len; i++) {
final JSONObject obj = ja.optJSONObject(i);
if (obj != null) {
result.add(obj);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment