How to Sort JSON Array from JSON Objects in Android?

前端 未结 5 1960
醉话见心
醉话见心 2020-12-10 19:25

I have a JSON array, and I want to sort it Depending on the name and too alphabetically. My Json is as follows.

[
    {
        \"UserID\": 77,
        \"Inv         


        
5条回答
  •  猫巷女王i
    2020-12-10 19:57

    On the Android side you generally won't sort objects in JSON format. If they do need to be sorted before you retrieve them, that is something that should occur on the backend.

    Alternatively, and this is very common, you will parse the JSON objects into local Java objects (or Collections of objects), and then you can use a comparator to sort the collection based on a certain property that exists within all objects in the collection.

    Fortunately both of these tasks have been asked and answered many times before. For more information on parsing JSON see How to parse JSON in Android. For more information on sorting objects in a collection see Android-java- How to sort a list of objects by a certain value within the object.

提交回复
热议问题