![]()
1 /// <summary>
2 /// 获取天气预报信息
3 /// </summary>
4 /// <returns></returns>
5 public BaiduTQ GetWeather()
6 {
7 // GetCity()获得的信息解析后,填充丰台部分
8 string url = @"http://api.map.baidu.com/telematics/v3/weather?location=丰台&output=json&ak=hXWAgbsCC9UTkBO5V5Qg1WZ9";
9
10 HttpWebRequest webRequest = HttpWebRequest.Create(url) as HttpWebRequest;
11 webRequest.Method = "GET";
12 webRequest.ContentType = "text/html";
13
14 using(StreamReader sr = new StreamReader(webRequest.GetResponse().GetResponseStream()))
15 {
16 string str = sr.ReadToEnd();
17 BaiduTQ b = JsonConvert.DeserializeObject<BaiduTQ>(str);
18
19 return b;
20 }
21 }
获取天气预报信息
![]()
1 public class BaiduTQ
2 {
3 public int error { get; set; }
4 public string status { get; set; }
5 public string date { get; set; }
6 public List<BaiduResult> results { get; set; }
7 }
8
9 public class BaiduResult
10 {
11 public string currentCity { get; set; }
12 public string pm25 { get; set; }
13 public List<BaiduIndex> index { get; set; }
14 public List<BaiDuWeaterData> weather_data { get; set; }
15 }
16
17 public class BaiduIndex
18 {
19 public string title { get; set; }
20 public string zs { get; set; }
21 public string tipt { get; set; }
22 public string des { get; set; }
23 }
24
25 public class BaiDuWeaterData
26 {
27 public string date { get; set; }
28 public string dayPictureUrl { get; set; }
29 public string nightPictureUrl { get; set; }
30 public string weather { get; set; }
31 public string wind { get; set; }
32 public string temperature { get; set; }
33 }
BaiduTQ