package com.gobestsoft.core.util;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
/**
* java调用中央气象局天气预报接口
*
* @author RoninGirl
*
*/
public class WeatherUtil {
/**
* 获取一周天气
* 方 法 名:getWeekWeatherMap
* @param Cityid 城市编码
*/
public static List> getWeekWeatherMap(String Cityid)
throws IOException, NullPointerException {
// 连接中央气象台的API
URL url = new URL("http://m.weather.com.cn/data/" + Cityid + ".html");
URLConnection connectionData = url.openConnection();
connectionData.setConnectTimeout(1000);
// 得到1到6天的天气情况
List> list = new ArrayList>();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(
connectionData.getInputStream(), "UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = br.readLine()) != null)
sb.append(line);
String datas = sb.toString();
System.out.println(datas);
JSONObject jsonData = JSONObject.fromObject(datas);
JSONObject info = jsonData.getJSONObject("weatherinfo");
for (int i = 1; i <= 6; i++) {
// 得到未