Is there any easy way to sort a JSONArray of objects by an attribute in Android?
1 Answer
Perhaps using the Google GSON library you can deserialise the array to a typed collection of objects, and then using Collections perform a sort.
Look at 6th line in on the following link.. Looks a bit messy but might be quickest way..
http://sites.google.com/site/gson/gson-user-guide#TOC-Collections-Examples
4 Comments
ninjasense
I was hoping to avoid deserializing into objects as the objects contain a lot of data and cost a lot to process.
David Brown
Where is the JSON sourced from?
ninjasense
I get all the JSON via a webresponse string that I create a JSONArray from.
David Brown
Can you not perform the sort on the server side then so the data is already in the order you require before pulling it to the device?