I have a response coming from a web service, data is in JSON
form.
JSONObject event:-
{
"15:00":{"type":1,"status":null,"appointment_id":null},
"16:00":{"type":1,"status":null,"appointment_id":null},
"17:00":{"type":1,"status":null,"appointment_id":null},
"18:00":{"type":1,"status":"1","appointment_id":5}
}
I don't know the key values, they are random. So when i iterate the data using iterator by fetching keys
and hasNext()
. It returns the data but changes the order of coming data.
Iterator AppoinmentIter = event.keys();
while(AppoinmentIter.hasNext()){
String appointmentTime = (String)AppoinmentIter.next();
JSONObject appointmentDetails = event.getJSONObject(appointmentTime);
}
I want the data in exact order in which it is coming.
I checked this link, it suggests to use LinkedHashMap
. But here they are inserting the value by keys. And i don't know the keys in my data. So how can i iterate the data in correct order. Please help..