0

我正在获取我的 json 响应并对其进行解析,我能够分别获得以下模型和标识符(见下文)。现在,我只需要按模型对它们进行排序,不区分大小写。因此,如果我创建一个数组,那么仅按模型排序就会变得很困难,如果不是不可能的话,如果我进行哈希,我将无法创建重复的键(模型)。
那么对这个 json 响应进行排序的最佳方法是什么?谢谢 !!

 this is the model: 1 Series
  this is the identifier: Convertible
  this is the model: 1 Series
  this is the identifier: Coupe
  this is the model: 1 Series M
  this is the identifier: Coupe
  this is the model: 3 Series
  this is the identifier: Convertible
  this is the model: 3 Series
  this is the identifier: Coupe
  this is the model: 3 Series
  this is the identifier: Diesel
  this is the model: 3 Series
  this is the identifier: Sedan
  this is the model: 3 Series
  this is the identifier: Wagon
  this is the model: ALPINA B7
  this is the identifier: Sedan
  this is the model: ActiveHybrid 5
  this is the identifier: Sedan
  this is the model: ActiveHybrid 7
  this is the identifier: Sedan
  this is the model: ActiveHybrid X6
  this is the identifier: SUV
4

2 回答 2

0

为什么数组无法排序?这将起作用。

[["1 Series","Convertible"],["3 Series","Coupe"]].sort
于 2012-07-27T19:46:43.043 回答
0

我会选择一组对象,其类混合在Comparable中。你只需要实现<=>(又名“宇宙飞船”),然后你就可以调用sort你的数组。

于 2012-07-27T19:24:27.653 回答