worldweatheronline
不返回可由WebService客戶端使用的SOAP-XML。因此,您應該下載響應並使用許多REST服務進行解析。
string url = "http://free.worldweatheronline.com/feed/apiusage.ashx?key=" + apikey;
using (WebClient wc = new WebClient())
{
string xml = wc.DownloadString(url);
var xDoc = XDocument.Parse(xml);
var result = xDoc.Descendants("usage")
.Select(u => new
{
Date = u.Element("date").Value,
DailyRequest = u.Element("daily_request").Value,
RequestPerHour = u.Element("request_per_hour").Value,
})
.ToList();
}
而且它的問題如果XML或JSON類型?
不,最後你必須自己解析響應。
string url = "http://free.worldweatheronline.com/feed/apiusage.ashx?format=json&key=" + apikey;
using (WebClient wc = new WebClient())
{
string json = wc.DownloadString(url);
dynamic dynObj = JsonConvert.DeserializeObject(json);
var jArr = (JArray)dynObj.data.api_usage[0].usage;
var result = jArr.Select(u => new
{
Date = (string)u["date"],
DailyRequest = (string)u["daily_request"],
RequestPerHour = (string)u["request_per_hour"]
})
.ToList();
}
PS:我以前Json.Net解析JSON字符串
來源
2013-02-10 21:20:42
I4V
注意,這個問題是不是ASMX與ASHX。它是隨機的,而不是SOAP。 – 2013-02-10 18:07:40