考虑以下是我的数组
[
{"id":10,"name":"name10","valid":true},
{"id":12,"name":"name12","valid":false},
{"id":11,"name":"name11","valid":false},
{"id":9,"name":"name9","valid":true}
]
从中创建了一个JsonArray
,就像下面的代码一样:
//Create a JSON Parser using GSON library
objJsonParser = new JsonParser();
String strArrayText = [{"id":9,"name":"name9","valid":true}, ...]
JsonArray jsonArrayOfJsonObjects = objJsonParser.parse(strArrayText).getAsJsonArray();
现在,我正在尝试jsonArrayOfJsonObjects
根据name
字段进行排序。
期望的输出:
[
{"id":9,"name":"name9","valid":true},
{"id":10,"name":"name10","valid":false},
{"id":11,"name":"name11","valid":false},
{"id":12,"name":"name12","valid":true}
]
任何人都可以用关于 Java 和 Gson 的最佳方法来帮助解决这个问题吗?
非常感谢您的意见。