I will receive a JSON respond containing this:
{..."Weekday":[3,4,2],...} //numbers might not be in Ascending order
Then depending on what inside "Weekday" I will print out Sunday for 0, Monday for 1 and so on. So the text printed out for above would be;
"Tuesday,Wednesday,Thursday" //This should be in ascending order
How do i check and print what I want, the way I am doing this is like this:
JSONObject obj = new JSONObject(result); //result from backend
JSONObject DayOff = obj.getJSONObject("Weekday");
...
tvWeekdays = (TextView) getActivity().findViewById(R.id.tvWeekdays);
tvWeekdays.setText("The final result");
I am not sure with how to achieve this, I am thinking of maybe a while loop or if statement would help?
---UPDATE---
JSONArray array = obj.getJSONArray("Weekday");
if (array == null){
tvDayOff = (TextView) getActivity().findViewById(R.id.tvDayOff);
tvDayOff.setText("None");
}
// Create an int array to accomodate the numbers.
int[] numbers = new int[array.length()];
Arrays.sort(numbers);
// Extract numbers from JSON array.
for (int i = 0; i < array.length(); ++i) {
numbers[i] = array.optInt(i);
System.out.println(
DateFormatSymbols.getInstance().getWeekdays()[numbers[i]]
);
}