从中国天气网上获取天气数据并解析
2010-02-05 16:19
393 查看
中国天气网http://www.weather.com.cn/上提供了很多有价值的天气数据,包含全国到县级地区的天气数据。可惜的是没有很好的数据共享接口, 该网站上提供了各种各样的插件 能满足一般网站的需求,但是对于只需要天气数据的而言还是不大方便~ 不过通过下面的方式可以获取指定地点的天气数据。 C#代码 public string GetWeatherData()
{
string path = " http://m.weather.com.cn/data/";
string[] citys = { "******", "******", "******", "******", "******" };// 城市编号 自己去找吧~
string html = "{\"result\":["; //返回的数据
foreach (string url in citys)
{
WebRequest req = WebRequest.Create(path + url + ".html");
WebResponse res = req.GetResponse();
Stream receiveStream = res.GetResponseStream();
Encoding encode = Encoding.GetEncoding("UTF-8");
StreamReader sr = new StreamReader(receiveStream, encode);
string temp = sr.ReadToEnd();
temp = temp.Substring(0, temp.Length - 1); temp += "},";
html += temp;
}
html = html.Substring(0, html.Length - 1);
html += "]}";
return html; }
这样最后得到的是一个json对象,我们在程序里进行解析就行了。
weatherinfo对象部分数据说明--------- index_uv:紫外线指数
index :穿衣指数
temp1 :温度
weather1:天气情况
fx1 :风向
fl1 :风力
date_y :日期
fchh :时间
{
string path = " http://m.weather.com.cn/data/";
string[] citys = { "******", "******", "******", "******", "******" };// 城市编号 自己去找吧~
string html = "{\"result\":["; //返回的数据
foreach (string url in citys)
{
WebRequest req = WebRequest.Create(path + url + ".html");
WebResponse res = req.GetResponse();
Stream receiveStream = res.GetResponseStream();
Encoding encode = Encoding.GetEncoding("UTF-8");
StreamReader sr = new StreamReader(receiveStream, encode);
string temp = sr.ReadToEnd();
temp = temp.Substring(0, temp.Length - 1); temp += "},";
html += temp;
}
html = html.Substring(0, html.Length - 1);
html += "]}";
return html; }
这样最后得到的是一个json对象,我们在程序里进行解析就行了。
weatherinfo对象部分数据说明--------- index_uv:紫外线指数
index :穿衣指数
temp1 :温度
weather1:天气情况
fx1 :风向
fl1 :风力
date_y :日期
fchh :时间
相关文章推荐
- window phone7.1 天气预报教程(二)WebClient获取天气和json数据解析显示
- Android解析中国天气接口JSon数据,应用于天气查询!
- 网上在线获取天气数据
- android 从网上解析Json获取天气情况
- Android解析中国天气接口JSon数据,应用于天气查询!
- Android 天气预报 接口数据获取 from 中国气象网
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
- <WP7>(三)手把手教你写天气预报程序:运用WebClient获取天气和json数据解析
- C#实现解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市的方法
- <WP7>(三)手把手教你写天气预报程序:运用WebClient获取天气和json数据解析
- 【Android应用开发】-(17)获取Google天气预报通过Xml和JSON解析数据
- [python]解析通达信盘后数据获取历史日线数据
- js解析php返回的json数据无法获取length的问题分析
- 内部类解析sql查询获取的数据结果
- Android 获取新浪天气预报数据
- python解析Yahoo的XML格式的天气预报,获取当天和近期几天的天气:
- 《项目经验》--通过js获取前台数据向一般处理程序传递Json数据,并解析Json数据,将前台传来的Json数据写入数据库表中
- android客户端从服务器端获取json数据并解析
- 网上获取xml并解析