Is there any easy way to sort a JSONArray of objects by an attribute in Android?
Asked
Active
Viewed 2,995 times
0
-
Possible duplicate of [How can I sort a JSONArray in JAVA](http://stackoverflow.com/questions/19543862/how-can-i-sort-a-jsonarray-in-java) – Vito Gentile Nov 15 '16 at 14:59
1 Answers
1
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

David Brown
- 3,021
- 3
- 26
- 46
-
I was hoping to avoid deserializing into objects as the objects contain a lot of data and cost a lot to process. – ninjasense Jan 28 '11 at 21:58
-
-
I get all the JSON via a webresponse string that I create a JSONArray from. – ninjasense Jan 31 '11 at 21:00
-
1Can 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? – David Brown Feb 01 '11 at 08:16