中国天气网接口地址:”http://wthrcdn.etouch.cn/WeatherApi?citykey=” + weatherCityCode(为城市code);

下面是转化过程中我们需要用到的方法(序列化的实体类在文章结尾附)

   string weatherInfoUrl = "http://wthrcdn.etouch.cn/WeatherApi?citykey=" + weatherCityCode;
string weatherstr = getHtml2(weatherInfoUrl);
resp tempInfo = XmlDeSeralizer<resp>(weatherstr);

  

转化过程中需要用到的方法

        private static string GetHtml(string url)
{
StringBuilder s = new StringBuilder(102400);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
Head(response);
GZipStream g = new GZipStream(response.GetResponseStream(), CompressionMode.Decompress);
byte[] d = new byte[20480];
int l = g.Read(d, 0, 20480);
while (l > 0)
{
s.Append(Encoding.UTF8.GetString(d, 0, l));
l = g.Read(d, 0, 20480);
}
return s.ToString();
} private static void Head(HttpWebResponse r)
{
string[] keys = r.Headers.AllKeys;
for (int i = 0; i < keys.Length; ++i)
{
Console.WriteLine(keys[i] + " " + r.Headers[keys[i]]);
}
} public static T XmlDeSeralizer<T>(string xmlStr) where T : class,new()
{
XmlSerializer xs = new XmlSerializer(typeof(T));
using (StringReader reader = new StringReader(xmlStr))
{
return xs.Deserialize(reader) as T;
}
}

天气实体类

    public class resp
{
public string city { get; set; }
public string updatetime { get; set; }
public string wendu { get; set; }
public string fengli { get; set; }
public string shidu { get; set; }
public string fengxiang { get; set; }
public environment environment { get; set; }
public alarm alarm { get; set; }
public List<weather> forecast { set; get; }
}
public class environment
{
public string aqi { get; set; }
public string pm25 { get; set; }
public string suggest { get; set; }
public string quality { get; set; }
public string MajorPollutants { get; set; }
public string time { get; set; }
}
public class alarm
{
public string cityName { get; set; }
public string alarmType { get; set; }
public string alarmDegree { get; set; }
public string alarmText { get; set; }
public string alarm_details { get; set; }
public string standard { get; set; }
public string suggest { get; set; }
}
public class weather
{
public string date { get; set; }
public string high { get; set; }
public string low { get; set; }
public climate day { get; set; }
public climate night { get; set; }
}
public class climate
{
public string type { get; set; }
public string fengxiang { get; set; }
public string fengli { get; set; }
}

  

C#获取中国天气网免费天气预报信息的更多相关文章

  1. python3抓取中国天气网不同城市7天、15天实时数据

    思路:1.根据city.txt文档来获取不同城市code2.获取中国天气网7d和15d不同城市url3.利用requests库请求url获取html内容4.利用beautifulsoup获取7d和15 ...

  2. 中国天气网-天气预报接口api

    中国天气网地址:http://www.weather.com.cn 请求服务 : 查询实时天气信息 http://www.weather.com.cn/data/sk/101110101.html 在 ...

  3. 天气预报接口api(中国天气网)

    中国天气weather.comhttp://m.weather.com.cn/data/101110101.html(六天预报) http://www.weather.com.cn/data/sk/1 ...

  4. C#实现中国天气网XML接口测试

    点击链接查看中国天气网接口说明,最近想研究一下接口测试,源于最近一次和某公司的技术总监(交大校友)谈话,发现接口测试的需求是比较大的,于是想要研究一下. 好不容易在网上找到了一个关于中国天气网的接口说 ...

  5. [转载]中国天气网API

    最近在做个网站要用到天气网的api,在网上找了些参考资料,这篇文章对天气网api的介绍比较详细,所以转载之,谢谢原作者的辛勤劳动和奉献精神. 原文地址:http://g.kehou.com/t1033 ...

  6. 中国天气网API接口

    http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data/cityinfo/101010100.h ...

  7. Android解析中国天气网的Json数据

    在Android开发中.一般的APP都是通过获取server端的数据来更新UI.从server获取到的数据能够是Json.它的数据量要比XML要小,这里解析中国天气网上获取的数据,尽管已经不再更新了. ...

  8. a中国天气网pi(json格式)

    http://m.weather.com.cn/data/101050101.html 此接口的回报格式例如以下 { "weatherinfo": { "city&quo ...

  9. 中国天气网API

    中国天气网有三个 API 适用于不同场合的使用. http://m.weather.com.cn/data/101050101.html 这个接口返回的格式如下. { "weatherinf ...

随机推荐

  1. Django之setting文件

    Django之setting文件 转载:https://www.jb51.net/article/128678.htm 目录 设置语言.时区 app路径 数据库配置 静态文件配置 中间件 sessio ...

  2. AM335X启动(转)

    AM335x启动   参考文件: 1.TI.Reference_Manual_1.pdf http://pan.baidu.com/s/1c1BJNtm 2.TI_AM335X.pdf http:// ...

  3. 记录下这几天使用 GitHub 碰到的问题

    1.在 GitHub 上为新项目创建一个库时,默认是不使能主页功能的 如果你想要使用 GitHub 的主页功能做一个博客或一份简历,需要人为设置一下.如下图: 制作简历,这里有一份更详细的参考:如何在 ...

  4. 835.Hamming距离

    描述 两个整数的Hamming距离是对应比特位不同的个数. 给定两个整数x和y,计算两者的Hamming距离. 0 ≤ x, y < 2^31. 您在真实的面试中是否遇到过这个题? 样例 输入: ...

  5. QtQuick自定义主题以及控件样式指引

    自定义控件样式 请在Qt帮助索引中输入Customizing a Control进行查看 不过实际用下来感觉除非你想自己实现一套效果复杂的UI或是创造一个全新控件,比如:给UI添加模糊.虚化等Shad ...

  6. [ONTAK2015]OR-XOR

    [ONTAK2015]OR-XOR 题目大意: 一个长度为\(n(n\le5\times10^5)\)的序列\(A(0\le A_i\le10^{18})\),将其分为恰好\(m\)个连续段,设每一段 ...

  7. POJ 水题(刷题)进阶

    转载请注明出处:優YoU http://blog.csdn.net/lyy289065406/article/details/6642573 部分解题报告添加新内容,除了原有的"大致题意&q ...

  8. 简单配置umiJS学习笔记

    最近跟着Antd-Pro官方教程学习umi,这里给大家推荐一下这个教程,特别适合初学者学习,教程涉及了AntD,AntD-Pro,umiJS,dvaJS等框架知识. 学习过程中跟着教程做了个Demo, ...

  9. BZOJ1515 : [POI2006]Lis-The Postman

    首先,如果这个图本身就不存在欧拉回路,那么显然无解. 对于每个子串: 1.如果里面有不存在的边,那么显然无解. 2.如果里面有一条边重复出现,那么显然也无解. 3.对于每条边,维护其前驱与后继,若前驱 ...

  10. JavaScrip两个函数的设置为回调

    1.javascript异步编程之回调函数 function fn2(data){ alert(data) } function fn1(callback){ var data = 12+1; cal ...