I have a response coming from a web service, the 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 do not know the key values, they are random. Therefore, when I repeat the data using an iterator, choosing keys and hasNext() . It returns data, but reorders the incoming data.
Iterator AppoinmentIter = event.keys(); while(AppoinmentIter.hasNext()){ String appointmentTime = (String)AppoinmentIter.next(); JSONObject appointmentDetails = event.getJSONObject(appointmentTime); }
I want the data in the exact order in which it goes. I checked this link, it suggests using LinkedHashMap . But here they insert the key value. And I do not know the keys in my data. So how can I iterate over the data in the correct order. Please, help..
source share