import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;import org.json.JSONObject;public class Test04 { public static void main(String[] args) throws IOException {
URL url=new URL("http://www.weather.com.cn/data/cityinfo/101010100.html");
InputStream is=url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String lines;
while ((lines = reader.readLine()) != null) {
sb.append(lines);
}
reader.close();
JSONObject json = new JSONObject(sb.toString());
JSONObject array=json.getJSONObject("weatherinfo");
System.out.println("城市:"+array.getString("city")+"\t"+"最高温度:"+array.getString("temp1")+"\t"+"最低温度:"+array.getString("temp2"));
}}
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;import org.json.JSONObject;public class Test04 { public static void main(String[] args) throws IOException {
URL url=new URL("http://www.weather.com.cn/data/cityinfo/101010100.html");
InputStream is=url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String lines;
while ((lines = reader.readLine()) != null) {
sb.append(lines);
}
reader.close();
JSONObject json = new JSONObject(sb.toString());
JSONObject array=json.getJSONObject("weatherinfo");
System.out.println("城市:"+array.getString("city")+"\t"+"最高温度:"+array.getString("temp1")+"\t"+"最低温度:"+array.getString("temp2"));
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货