@Test
public void testWendu() throws Exception {
String[] parameters = {"北京", "上海", "深圳", "广州"};
ArrayList<String> list = new ArrayList();
for (int i = 0; i < parameters.length; i++) {
httpclient httpGet = new httpclient();
JSONObject jsonObject = httpGet.sendGet(Url, "city=" + parameters[i]);
// String wenduOfYestoday = json.getJSONObject("data").getJSONObject("yesterday").getString("high");
JsonPath json = new JsonPath();
String expression = "$..yesterday.high";
String wenduOfYestoday = json.JsonPath(jsonObject.toString(), expression);
System.out.println(wenduOfYestoday);
wenduOfYestoday = wenduOfYestoday.split("( )|(℃)")[1];
list.add(wenduOfYestoday);
sleep(5000);
}
// Collections.sort(list);
// System.out.println(list.toString());
boolean flag = true;
for (int i = 0; i < list.size(); i++) {
flag = false;
for (int j = 0; j < list.size() - 1; j++) {
float value1 = Float.parseFloat(list.get(j));
float value2 = Float.parseFloat(list.get(j + 1));
if (value1 > value2) {
list.set(j, String.valueOf(value2));
list.set(j + 1, String.valueOf(value1));
flag = true;
}
}
if (flag == false) {
break;
}
}
System.out.println("排序后:" + list.toString());
}
xclient 了解一下?