获取百度天气信息
//获取链接 URL url = new URL("http://api.map.baidu.com/telematics/v3/weather?location=guangzhou&output=JSON&ak=XXX"); //打开链接 URLConnection conn = url.openConnection(); //设置访问超时 conn.setConnectTimeout(1000); //获取返回流数据 BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); String line = null; //创建流装载容器 StringBuilder sb = new StringBuilder(); //读取返回内容 while((line = br.readLine())!=null){ sb.append(line); } String datas = sb.toString();