gpt4 book ai didi

C# 与雅虎天气 api

转载 作者:太空宇宙 更新时间:2023-11-03 21:25:11 25 4
gpt4 key购买 nike

<分区>

我的目的是开发一个 C# 表单应用程序,从 yahoo weather api 检索天气数据。我需要程序从雅虎获取天气数据并在相应的文本输入中检索。代码如下..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using System.Web;
using System.Speech.Recognition;
using System.Speech.Synthesis;

namespace weather
{
public partial class Form1 : Form
{
string Temperature;
string Condition;
string Humidity;
string WindSpeed;
string Town;
string TFCond;
string TFHigh;
string TFLow;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void GetWeather()
{
string query = String.Format("http://weather.yahooapis.com/forecastrss?w=1319153");
//string query = String.Format("http://weather.yahooapis.com/forecastrss?w=2502265");
XmlDocument wData = new XmlDocument();
wData.Load(query);

XmlNamespaceManager manager = new XmlNamespaceManager(wData.NameTable);
manager.AddNamespace("yweather","http://xml.weather.yahoo.com/ns/rss/1.0");

XmlNode channel = wData.SelectSingleNode("rss").SelectSingleNode("channel");
XmlNodeList nodes = wData.SelectNodes("/rss/channel/item/yweather:forecast", manager);

Temperature = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["temp"].Value;

Condition = channel.SelectSingleNode("item").SelectSingleNode("yweather:condition", manager).Attributes["text"].Value;

Humidity = channel.SelectSingleNode("yweather:atmosphere", manager).Attributes["humidity"].Value;

WindSpeed = channel.SelectSingleNode("yweather:wind", manager).Attributes["speed"].Value;

Town = channel.SelectSingleNode("yweather:location", manager).Attributes["city"].Value;

TFCond = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["text"].Value;

TFHigh = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["high"].Value;

TFLow = channel.SelectSingleNode("item").SelectSingleNode("yweather:forecast", manager).Attributes["low"].Value;
}

private void button1_Click(object sender, EventArgs e)
{
textBox1.AppendText(Temperature);
textBox2.AppendText(Humidity);
}

}
}

gui如下...

enter image description here

我需要善良的程序员的帮助。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com