package testCase;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import Trigger.httpclient;
import junit.framework.Assert;
import net.sf.json.JSONObject;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class Test_1 {
    @Test
    public void testMethod() throws Exception {
        List<String> list = Arrays.asList("上海","北京","深圳","广州");
        List<String> wenduList=getYesterdayWendu(list);
        paixu(wenduList);
        System.out.println(wenduList);
    }
    private List<String> getYesterdayWendu(List<String> city)throws Exception{
        String  Url="https://www.sojson.com/open/api/weather/json.shtml";
        List<String> wenduList = new ArrayList<>();
        for(int i=0;i<city.size();i++) {
            String Parameter = "city=" + city.get(i);
            httpclient httpGet = new httpclient();
            JSONObject json = httpGet.sendGet(Url, Parameter);
            String JsonStr = JsonPath.JsonPath(json.toString(), "$..yesterday.high");
            String Wendu = city.get(i) + ":" + JsonStr.substring(JsonStr.indexOf("温") + 2, JsonStr.indexOf("℃"));
            wenduList.add(Wendu);
            System.out.println(Wendu);
            Thread.sleep(4000);
        }
        return wenduList;
    }
    private List paixu(List<String> l){
        int length = l.size();
        for(int i=0; i<length-1; i++){
            for(int j=i+1; j<length; j++) {
                String a = l.get(i);
                String b = l.get(j);
                if (Float.parseFloat(a.split(":")[1]) < Float.parseFloat(b.split(":")[1])) {
                    l.set(i, b);
                    l.set(j, a);
                }
            }
        }
        return l;
    }
}
好东西要大力支持
非常感谢分享!