C#作业总结 (4)

时间关系,先总结一下天气信息获取部分,给出详细的步骤

.

在URL里面输入  http://www.webxml.com.cn/WebServices/WeatherWebService.asmx ,添加引用就行 。

准备工作已经做好,下面给出我里面大部分的代码

        private void GetWeather()
        {
            string city = "西安";
            try
            {
                cn.com.webxml.www.WeatherWebService wws = new cn.com.webxml.www.WeatherWebService();       //实例化
                string[] wwsArray = wws.getWeatherbyCityName(city);            //获取信息  
                string[] info = wwsArray[10].Split(new char[] { '' });       //分割  注意 这里的 ;  不是 ;   
                m_WeatherAllInfo[0] = info[0].Substring(info[0].LastIndexOf('') + 1, info[0].Length - info[0].LastIndexOf(''));      //气温 注意零下的气温 
                m_WeatherAllInfo[1] = wwsArray[6].Substring(wwsArray[6].LastIndexOf(' ') + 1);     //云状况
                m_WeatherAllInfo[2] = info[1].Substring(info[1].IndexOf('') + 1);    //风向
                m_WeatherAllInfo[3] = info[2].Substring(info[2].IndexOf('') + 1);    //湿度
                m_WeatherAllInfo[4] = info[4].Substring(info[4].IndexOf('') + 1);    //紫外线强度
                m_WeatherAllInfo[5] = wwsArray[5];                                     //当天气温
                m_WeatherAllInfo[6] = @".ImageWeatherSmallWeather_" + wwsArray[8];      //图片信息  
                m_WeatherAllInfo[7] = wwsArray[12];
                m_WeatherAllInfo[8] = @".ImageWeatherSmallWeather_" + wwsArray[15];
                m_WeatherAllInfo[9] = wwsArray[17];
                m_WeatherAllInfo[10] = @".ImageWeatherSmallWeather_" + wwsArray[20];
                string tmp = wwsArray[8].Substring(0, wwsArray[8].IndexOf('.'));
                pictureWeather.Image = Image.FromFile(string.Format(@".ImageWeatherBigWeathera_{0}.ico", tmp));
                m_SuccessWeather = true;
            }
            catch
            {
                m_SuccessWeather=false; 
            }
        }

上面大部分是操作字符串的代码,给出天气图标素材资源的下载 http://download.csdn.net/detail/zhoupeng39/8257009

具体的程序就不发了,发一张截图

洗洗睡了

原文地址:https://www.cnblogs.com/fightfuture/p/4162089.html