使用CSahrp解析和风天气api获取济南实时天气数据的数据代码
时间: 2024-06-10 11:06:20 浏览: 21
以下是使用CSharp解析和风天气API获取济南实时天气数据的示例代码:
```
using System;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
class Program
{
static void Main(string[] args)
{
string url = "https://devapi.qweather.com/v7/weather/now?location=101120101&key=YOUR_KEY";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string jsonStr = reader.ReadToEnd();
JObject jsonObj = JObject.Parse(jsonStr);
string temp = jsonObj["now"]["temp"].ToString();
string text = jsonObj["now"]["text"].ToString();
Console.WriteLine("济南实时天气:" + text + ",温度:" + temp + "℃");
}
}
```
请将代码中的YOUR_KEY替换为你的和风天气API密钥。该代码通过和风天气API获取位于101120101地区(济南)的实时天气数据,并在控制台中输出天气状况和温度。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)