Search code examples
androidjsonsortingarraysalphabetical-sort

How to sort a JSONArray of JSONObjects alphabetic based on a field in the JSONObject


I got a JSONArray of JSONObjects.

How can i sort the JSONArray alphabetic based on a string field in the JSONObject?


Solution

  • Don't think you can do that with JSONArray and JSONObject classes. You'd have to deserialize to other Java classes and use those functions to do your sorting.

    The best way to deserialize might be to use the Google GSON library: https://sites.google.com/site/gson/gson-user-guide#TOC-Collections-Examples