How to sort JSONArray in android

后端 未结 3 1919
谎友^
谎友^ 2021-01-23 16:21

How to sort JSONArray by its Tag name with ascending and descending on android.

In my application i have a JSON like the following and need to display the data according

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-23 16:32

    It seems to me like the easiest way to do it, rather than "sorting the JSON Array" as you suggest, is to just parse the whole thing into a data structure which contains the information like so:

    class Results {
         String user_id;
         Strung comment_id;
    }
    

    Save this as an ArrayList or a [insert favourite List structure].

    Once you've parsed the entire JSON Array, you can then sort your ArrayList based on the user_id field using Collections.sort, giving you them in order

提交回复
热议问题