wp7天气预报源代码(二序列化谷歌数据)公布源代码下载地址
在上一篇http://www.zzzyk.com/kf/201203/125357.html 文章里已经介绍了这个应用由于代码过多,和繁杂的前台页面效果代码,没办法在博文中说明白,还有很多网友要求我公布源代码项目。在文章的最下面我提供了源代码的下载地址。
作者QQ:29992379
这个天气预报用的是谷歌的API,我特意写了个工具类用来序列化返回的数据,本文中主要介绍这个工具类。
代码如下:
using System;
using System.Linq;
using System.Xml.Linq;
namespace GoogleWeather
{
public static class GoogleWeatherHelper
{
/// <summary>
/// 获取城市以及省
/// </summary>
/// <param name="xmlWeather">xml数据</param>
/// <returns></returns>
public static string GetCity(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("city").Attribute("data").Value;
}
/// <summary>
/// 获取中文城市名称
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetPostalCode(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("postal_code").Attribute("data").Value;
}
/// <summary>
/// 获取预报的日期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetForecastDate(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_information").First();
return forecast_information.Element("forecast_date").Attribute("data").Value;
}
/// <summary>
/// 获取湿度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetHumidity(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
return forecast_information.Element("humidity").Attribute("data").Value;
}
/// <summary>
/// 获取风向
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetWindCondition(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("current_conditions").First();
return forecast_information.Element("wind_condition").Attribute("data").Value;
}
/// <summary>
/// 获取今天星期
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayWeek(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("day_of_week").Attribute("data").Value;
}
/// <summary>
/// 获取今天最低温度
/// </summary>
/// <param name="xmlWeather"></param>
/// <returns></returns>
public static string GetTodayLow(XElement xmlWeather)
{
XElement forecast_information = xmlWeather.Descendants("forecast_conditions").First();
return forecast_information.Element("low").Attribute("data").Value;
}
/// <summary>
/// 获取今天最高温度
/// </summary>
补充:移动开发 , Windows Phone ,