我有来自json文件的整数列表,并打印完整列表。在对该列表进行排序后,它将以不同的方式打印
List<Integer> list = new ArrayList<Integer>(keys);
System.out.println("list is :" + list);
Collections.sort(list);
System.out.println("after sorting is:"+list);
o / p list:
[338, 339, 332, 333, 159, 330, 158, 331, 157, 336, 156, 337, 155,etc...0,1,14]
而不是在0,1,2
等排序...以下面的方式排序:
是:
[0, 1, 10, 100, 101, 102, 103, 104, 105,etc..]
代码:
response = httpUtil.getResponse(aperture_url);
parser = new JSONParser();
object = parser.parse(((String) response));
jsonObject = (JSONObject) object;
aperture_details = (JSONObject) jsonObject.get("response");
historic_price = (JSONObject) aperture_details.get("historic_price");
System.out.println("historic_price:" + historic_price);
keys = historic_price.keySet();
List<Integer> list = new ArrayList<Integer>(keys);
System.out.println("list is :" + list);
Collections.sort(list);
System.out.println("after sorting is:"+list);
答案 0 :(得分:0)
请提供变量DAY
!!
你说你是从JSON文件中获取的,所以我想你使用keys
如果是,键应为数组。
尝试改变
JSON.parse(...content of your file here...)
到
List<Integer> list = new ArrayList<Integer>(keys);