gpt4 book ai didi

java - 如何在没有外部库的情况下在java中按字母顺序对json数据进行排序?

转载 作者:行者123 更新时间:2023-12-02 06:42:19 26 4
gpt4 key购买 nike

我有以下 json:

       {"attendance_data":
{"date":"26-Sep-2013","users":
[{"uid":"2","status":"present","name":"xyz"},
{"uid":"3","status":"present","name":"mno"},
{"uid":"4","status":"present","name":"cde "}
,{"uid":"5","status":"present","name":"wxy"}]}}

我想按字母顺序排序:

 {"attendance_data":{"date":"26-Sep-2013","users":
[{"uid":"2","status":"present","name":"cde"},
{"uid":"3","status":"present","name":"mno"},
{"uid":"4","status":"present","name":"wxy "},
{"uid":"5","status":"present","name":"xyz"}]}}

没有外部库是否可以?

最佳答案

使用包含变量的自定义对象将 JSONArray 加载到 ListArray,对其进行排序,然后从列表创建 JSONArray。这是一个小步行,但会做你想做的事。

关于java - 如何在没有外部库的情况下在java中按字母顺序对json数据进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19023219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com