How to remove duplicate and sort objects from JSONArray using Java

后端 未结 3 1146
生来不讨喜
生来不讨喜 2021-01-02 16:38

My JSON is:

[
   {
      \"distance\":32,
      \"stationCode\":\"MIG\",
      \"name\":\"Midghat\",
      \"platforms\":\"2\"
   },
   {
      \"distance\":         


        
3条回答
  •  误落风尘
    2021-01-02 17:30

    There is no direct way to that but you can follow the way mentioned bellow:

    1. Transform JsonObject to Java Object list using org.codehaus.jackson.map.ObjectMapper

    2. Use a Java Map to make unique (put key = stationCode, javaObject as object)

    3. Sort the map data based on distance.

提交回复
热议问题