0

Is there any easy way to sort a JSONArray of objects by an attribute in Android?

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I was hoping to avoid deserializing into objects as the objects contain a lot of data and cost a lot to process.
Where is the JSON sourced from?
I get all the JSON via a webresponse string that I create a JSONArray from.
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.