才看到你想要的是前台代码, 这是后台的
private string GetWeather(string cityCode)
{
string weather = string.Empty
if (cityCode == "" || string.IsNullOrEmpty(cityCode)) { cityCode = "seoul"}
XmlDocument document1 = new XmlDocument()
document1.Load("http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text=" + cityCode + "&format=xml")
XmlNodeList nodes1 = document1.GetElementsByTagName("woeid")
string strWoeid = nodes1[0].InnerText
XmlDocument document = new XmlDocument()
document.Load("http://weather.yahooapis.com/forecastrss?w=" + strWoeid + "&u=c")
XmlNodeList nodes = document.GetElementsByTagName("forecast",
@"http://xml.weather.yahoo.com/ns/rss/1.0")
foreach (XmlNode node in nodes)
{
Console.WriteLine("日期:{0},星期:{1},天气:{2},温度:{3}°C 至 {4}°C",
node.Attributes["date"].InnerText,
node.Attributes["day"].InnerText,
node.Attributes["text"].InnerText,
node.Attributes["low"].InnerText,
node.Attributes["high"].InnerText)
//FToC(int.Parse(node.Attributes["low"].InnerText)),
// FToC(int.Parse(node.Attributes["high"].InnerText)))
// //woeid
// // http://query.yahooapis.com/v1/public/yql?q=select * from geo.places where text="Wonju"&format=xml
}
return weather
}
中国天气网的有点问题,可以用下面api,你直接放浏览器里打开就会显示结果http://api.tocus.com.cn/weather2.php?send=北京
显示结果为
{"city":"北京","weather":"晴~阴","temp1":"26℃","temp2":"11℃"}
你可以参考下,天气api接口
http://www.tocus.com.cn/?send=article_show&id=105&class=2