框架师 2021-03-11 15:21 采纳率: 93.3%
浏览 104
已采纳

如何将转换为json的数据进行排序并去重呢

[{
        "time": "2021-03-05T06:33:58.207Z",
        "ln": "celGGIO1.AnIn70.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.21Z",
        "ln": "celGGIO1.AnIn70.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.214Z",
        "ln": "celGGIO1.AnIn70.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.22Z",
        "ln": "celGGIO1.AnIn70.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.231Z",
        "ln": "celGGIO1.AnIn71.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.235Z",
        "ln": "celGGIO1.AnIn71.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.239Z",
        "ln": "celGGIO1.AnIn71.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.245Z",
        "ln": "celGGIO1.AnIn71.mag.f",
        "stVal": "null",
        "value": "20.3"
        }, {
        "time": "2021-03-05T06:33:58.254Z",
        "ln": "celGGIO1.AnIn72.mag.f",
        "stVal": "null",
        "value": "20.2"
        }, {
        "time": "2021-03-05T06:33:58.258Z",
        "ln": "celGGIO1.AnIn72.mag.f",
        "stVal": "null",
        "value": "20.2"
        }, {
        "time": "2021-03-05T06:33:58.262Z",
        "ln": "celGGIO1.AnIn72.mag.f",
        "stVal": "null",
        "value": "20.2"
        }, {
        "time": "2021-03-05T06:33:58.268Z",
        "ln": "celGGIO1.AnIn72.mag.f",
        "stVal": "null",
        "value": "20.2"
        }, {
        "time": "2021-03-05T06:33:58.28Z",
        "ln": "celGGIO1.AnIn73.mag.f",
        "stVal": "null",
        "value": "487.923"
        }, {
        "time": "2021-03-05T06:33:58.284Z",
        "ln": "celGGIO1.AnIn73.mag.f",
        "stVal": "null",
        "value": "487.923"
        }, {
        "time": "2021-03-05T06:33:58.288Z",
        "ln": "celGGIO1.AnIn73.mag.f",
        "stVal": "null",
        "value": "487.923"
        }, {
        "time": "2021-03-05T06:33:58.294Z",
        "ln": "celGGIO1.AnIn73.mag.f",
        "stVal": "null",
        "value": "487.923"
        }, {
        "time": "2021-03-05T06:33:58.305Z",
        "ln": "celGGIO1.AnIn74.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.308Z",
        "ln": "celGGIO1.AnIn74.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.313Z",
        "ln": "celGGIO1.AnIn74.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.319Z",
        "ln": "celGGIO1.AnIn74.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.33Z",
        "ln": "celGGIO1.AnIn75.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.334Z",
        "ln": "celGGIO1.AnIn75.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.339Z",
        "ln": "celGGIO1.AnIn75.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.345Z",
        "ln": "celGGIO1.AnIn75.mag.f",
        "stVal": "null",
        "value": "491.546"
        }, {
        "time": "2021-03-05T06:33:58.356Z",
        "ln": "celGGIO1.AnIn76.mag.f",
        "stVal": "null",
        "value": "484.3"
        }, {
        "time": "2021-03-05T06:33:58.359Z",
        "ln": "celGGIO1.AnIn76.mag.f",
        "stVal": "null",
        "value": "484.3"
        }, {
        "time": "2021-03-05T06:33:58.362Z",
        "ln": "celGGIO1.AnIn76.mag.f",
        "stVal": "null",
        "value": "484.3"
        }, {
        "time": "2021-03-05T06:33:58.368Z",
        "ln": "celGGIO1.AnIn76.mag.f",
        "stVal": "null",
        "value": "484.3"
        }, {
        "time": "2021-03-05T06:33:58.378Z",
        "ln": "celGGIO1.AnIn77.mag.f",
        "stVal": "null",
        "value": "490.338"
        }, {
        "time": "2021-03-05T06:33:58.381Z",
        "ln": "celGGIO1.AnIn77.mag.f",
        "stVal": "null",
        "value": "490.338"
        }, {
        "time": "2021-03-05T06:33:58.384Z",
        "ln": "celGGIO1.AnIn77.mag.f",
        "stVal": "null",
        "value": "490.338"
        }, {
        "time": "2021-03-05T06:33:58.39Z",
        "ln": "celGGIO1.AnIn77.mag.f",
        "stVal": "null",
        "value": "490.338"
        }, {
        "time": "2021-03-05T06:33:58.4Z",
        "ln": "celGGIO1.AnIn78.mag.f",
        "stVal": "null",
        "value": "489.13"
        }, {
        "time": "2021-03-05T06:33:58.403Z",
        "ln": "celGGIO1.AnIn78.mag.f",
        "stVal": "null",
        "value": "489.13"
        }, {
        "time": "2021-03-05T06:33:58.407Z",
        "ln": "celGGIO1.AnIn78.mag.f",
        "stVal": "null",
        "value": "489.13"
        }, {
        "time": "2021-03-05T06:33:58.413Z",
        "ln": "celGGIO1.AnIn78.mag.f",
        "stVal": "null",
        "value": "489.13"
        }, {
        "time": "2021-03-05T06:33:58.425Z",
        "ln": "celGGIO1.AnIn79.mag.f",
        "stVal": "null",
        "value": "485.507"
        }, {
        "time": "2021-03-05T06:33:58.43Z",
        "ln": "celGGIO1.AnIn79.mag.f",
        "stVal": "null",
        "value": "485.507"
        }, {
        "time": "2021-03-05T06:33:58.435Z",
        "ln": "celGGIO1.AnIn79.mag.f",
        "stVal": "null",
        "value": "485.507"
        }, {
        "time": "2021-03-05T06:33:58.441Z",
        "ln": "celGGIO1.AnIn79.mag.f",
        "stVal": "null",
        "value": "485.507"
        }, {
        "time": "2021-03-05T06:33:58.451Z",
        "ln": "celGGIO1.AnIn80.mag.f",
        "stVal": "null",
        "value": "481.884"
        }, {
        "time": "2021-03-05T06:33:58.455Z",
        "ln": "celGGIO1.AnIn80.mag.f",
        "stVal": "null",
        "value": "481.884"
        }, {
        "time": "2021-03-05T06:33:58.46Z",
        "ln": "celGGIO1.AnIn80.mag.f",
        "stVal": "null",
        "value": "481.884"
        }, {
        "time": "2021-03-05T06:33:58.467Z",
        "ln": "celGGIO1.AnIn80.mag.f",
        "stVal": "null",
        "value": "481.884"
        }]
  • 写回答

6条回答 默认 最新

  • l759692959 2021-03-12 09:29
    关注

    1.com.alibaba.fastjson

            JSONArray jsonArray = JSON.parseArray(text);
    

    2. jdk 1.8

            jsonArray = IntStream.rangeClosed(0, jsonArray.size() - 1).mapToObj(jsonArray::getJSONObject).sorted(Comparator.comparing((JSONObject jsonObject) -> jsonObject.getString("time")).thenComparing(jsonObject -> jsonObject.getString("value"))).distinct().collect(Collectors.toCollection(JSONArray::new));
    

    先按照time再按照value排序;

    3.输出查看结果

            jsonArray.forEach(System.out::println);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?