Sorting by some of the fields in Json Object

前端 未结 2 1893
孤街浪徒
孤街浪徒 2021-01-20 23:21

I have a Josn file containing array of objects like :

{
    \"tId\": \"Something\",
    \"StartTime\": \"05/29/2013 5:28:33 PM\",
    \"CompleteTime\": \"05/29/         


        
2条回答
  •  野性不改
    2021-01-20 23:45

    Your sorting routine will look something like this, depending on the specifics of how you do your JSON/Object mapping:

    Collections.sort(myObjectList, new Comparator() {
      @Override
      int compare(MyObject a, MyObject b) {
        if (a.getStartTime().equals(b.getStartTime())) {
          return a.getMachineName().compare(b.getMachineName());
        }
        return a.getStartTime().compare(b.getStartTime());
      }
    });
    

提交回复
热议问题