How to Sort JSON Array from JSON Objects in Android?

前端 未结 5 1962
醉话见心
醉话见心 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条回答
  •  甜味超标
    2020-12-10 20:06

    Firstly, parse the json data and add every json object to List of Object (e.g. Employee)

    List employees = parseJson(jsonDate);
    Collections.sort(employees, new EmployeeComparator());
    

    Here is the comparator implementation:

    class EmployeeComparator implements Comparator {
        @Override
        public int compare(Employee o1, Employee o2) {
            return o1.getName().compareTo(o2.getName());
        }
    }
    

提交回复
热议问题