新浪为我们提供了天气预报获取接口API
http://php.weather.sina.com.cn/xml.php?city=武汉&password=DJOYnieT8234jlsK&day=0 其中city=后面跟各城市的中文,比如北京,台北。。 day=后面接0 1 2 3 4 这个四个数字,0 表示当天的天气,1表示第二天的天气,以此类推。打开的是XML文件。
话不多说了,上代码:
public class GetWeather {
static String[] city={"北京","天津","上海","重庆","石家庄","太原","沈阳","长春","哈尔滨","南京","杭州","合肥","福州","南昌","济南","郑州","武汉","长沙","广州","海口","成都","贵阳","昆明","西安","兰州","西宁","拉萨","南宁","呼和浩特","银川","乌鲁木齐","香港","台北","澳门"}; //各个城市
static int[] day={0,1,2,3,4}; //哪一天的天气
static String weather; //保存