My code extract results of JSONObject, but, sometimes, the i value don’t begin to 1, and i have an error like that :
org.json.JSONException: No value for 1
My code :
JSONObject obj = new JSONObject(result);
for(int i=1;i<=14;i++) {
JSONArray arr = obj.getJSONArray(""+i);
extraction(arr, i);
}
I want to test before the extraction if the object code (i) exists or not. How i can do this ?
use
obj.optJSONArray(name)the response will be null if the name does not exists.