封装的方法:
public String getInfo() {
StringBuffer buffers = new StringBuffer();
try {
URL url = new URL(URL1 + city1.getCity());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
int code = 0;
code = conn.getResponseCode();
if (code != 0 && code == 200) {//请求成功
reader = new
InputStreamReader(conn.getInputStream(), "UTF-8");
char[] charArr = new char[1024 * 8];
int len = 0;
while ((len = reader.read(charArr)) != -1) {
//字符串数组转字符串
str = new String(charArr, 0, len);
}
reader.close();
JSONObject obj = new JSONObject(str);
in