【发布时间】:2016-10-26 10:18:17
【问题描述】:
我有一个通过 API 获得的 JSONObject。 是这样的:
{
"wash_method": 305,
"fragrance": 1156,
"sweater_type": 260,
"dial_color": 66475,
"charger_type": 2581,
"pen_drives_interface": 563,
"watches_type": 66475,
"processor": 3270,
"frame_material": 1211,
"dial_shape": 66475,
"os": 3308
}
我想根据值对其进行排序以获得如下结果:
{
"dial_shape": 66475,
"dial_color": 66475,
"watches_type": 66475,
"os": 3308,
"processor": 3270,
"charger_type": 2581,
"frame_material": 1211,
"fragrance": 1156,
"pen_drives_interface": 563,
"wash_method": 305,
"sweater_type": 260,
}
如您所见,前 3 项具有相似的价值,因此可以以任何方式排列。
我怎样才能做到这一点? (有没有办法以最小的复杂性做到这一点?)
【问题讨论】:
-
JSON 对象没有“排序”的概念
-
API 开发人员必须在给您回复之前完成此操作
-
JSONObject 是一组无序的名称/值对。所以你不能对它们进行排序。相反,您可以解析 Json 并存储在 List 中,并根据需要对列表进行排序。
-
@Baba 我需要提取数据并将前 15 个排序项(键、值)放入列表中。 ?
-
为什么不提取数据然后排序呢??
标签: java android json sorting jsonobject