For the given JSON:
{
"month": {
"days": {
"day1": {
"start": 13914323164815,
"duration": 15
},
"day2": {
"start": 13914123164815,
"duration": 56
}
}
}
}
I want to get the values for duration (in this case 15 and 56), compare them and return the smaller value. First i got the month object and this is what i tried next:
JSONObject days = myMonthObject.getJSONObject("days");
JSONArray daysArray = days.names();
for (short r = 0; r<daysArray.length();r++){
String dayObject = daysArray.getString(r);
JSONObject allDaysObject = days.getJSONObject(dayObject);
String duration = allDaysObject.getString("duration");
Log.w(TAG, "THE DURATION IS: " + duration);
}
On the first iteration I got the message: THE DURATION IS: 15, and on the second iteration: THE DURATION IS: 56.
Now how to preserve the first found value for duration and on the next iteration of daysArray loop (the value will be 56) to compare both and return and smaller?
Any help will be appreciated! :)