0
以前の質問で助けてくれてありがとうございました.Webサービス(これは同じデータだとします)を使用してURIからデータを読み込む方法が不思議でした。 http://www.google.com/ig/api?weather=paris 私はこのコードでtryiedが、それはうまくいきませんでした:WP7のWebサービス
public MainPage()
{
InitializeComponent();
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download_string_complete);
wc.DownloadStringAsync(new Uri("http://www.google.com/ig/api?weather=hammamet", UriKind.Absolute));
}
public void download_string_complete(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
ListBoxItem areaItem = null;
StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);
string day = String.Empty;
string low = String.Empty;
string high = String.Empty;
string condition = String.Empty;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name=="forecast_conditions")
{
WeatherElement welement = new WeatherElement();
switch (reader.Name)
{
case ("day_of_week"):
{
day = reader.ReadElementContentAsString();
areaItem = new ListBoxItem();
areaItem.Content = day;
friendsBox.Items.Add(day);
} break;
case ("low"):
{
low = reader.ReadElementContentAsString();
areaItem = new ListBoxItem();
areaItem.Content = low;
friendsBox.Items.Add(low);
} break;
case ("high"):
{
high = reader.ReadElementContentAsString();
areaItem = new ListBoxItem();
areaItem.Content = high;
friendsBox.Items.Add(high);
} break;
case ("condition"):
{
condition = reader.ReadElementContentAsString();
areaItem = new ListBoxItem();
areaItem.Content = condition;
friendsBox.Items.Add(condition);
} break;
}
}
}
}
}
}
あなたは「それは動作しませんでした」説明していただけます ここにURLリンクがですか? – CodeZombie
どうしてうまくいかなかったのですか?何が起こった?任意のエラー?もしあれば?どのコード行がそれらを引き起こしたのでしょうか? –
私はアプリケーションを実行すると、空の画面が表示されます(データを読み取っていません) – MarTech