You can call names() on a JSONObject to get a JSONArray of the names of its elements - this would let you do logic on them or retrieve their corresponding values dynamically.
names()
JSONObject
JSONArray
You can get all the attributes of a JSONObject like this
for(Iteraor key=jsonObject.keys();itr.hasNext();) { jsonObject.get(key.next());}
JSONObject obj = new JSONObject(json);for(Iterator<String> keys=obj.keys();keys.hasNext();) { obj.get(keys.next());}