I started building an Android app that uses a flat file for storage. The app doesn't store more than six records, and I'm familiar with JSON, so I just write out a JSONArray
to the file.
I just discovered today, though, that the Android JSON API doesn't include a remove()
option. Huh? Do I have to dump the array into another collection, remove it, then rebuild the JSONArray
? What's the point?
I use:
public static JSONArray removeFrom(JSONArray jsonArray, int pos){
JSONArray result = new JSONArray();
try {
for (int i = 0; i < jsonArray.length(); i++) {
if (i != pos) {
jsonArray.put(jsonArray.get(i));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With