alalonde alalonde - 1 year ago 67
Android Question

Why isn't there a remove(int position) method in Android's JSONArray?

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

to the file.

I just discovered today, though, that the Android JSON API doesn't include a
option. Huh? Do I have to dump the array into another collection, remove it, then rebuild the
? What's the point?

Answer Source

The point is that JSONArray and JSONObject are meant to (de)serialize data to JSON, not manipulate data. A remove() method may seem to make sense, but where's the limit? Would you expect to be able to access attributes on serialized objects? Access or update nested data structures?

The idea is, indeed, that you manipulate data structures "natively".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download