Yahoo! Search Web Services: Spelling Suggestion サンプルコード(C#) †
以下のコードを実行するには、xsd.exeで生成されたクラスが必要です。これを添付しておきます。
ArtistSearchResponse.cs 837件
[詳細]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
| | <%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string requestUrl =
"http://api.search.yahoo.com/AudioSearchService/V1/artistSearch";
requestUrl += "?appid=XXXXX";
requestUrl += "&artist=" + Server.UrlEncode(TextBox1.Text);
System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create(
requestUrl);
System.Net.HttpWebResponse response = null;
Yahoo.us.ArtistSearchResponse.ResultSet res;
try
{
response = (System.Net.HttpWebResponse)request.GetResponse();
System.IO.Stream strm = response.GetResponseStream();
System.Xml.Serialization.XmlSerializer serializer =
new System.Xml.Serialization.XmlSerializer(
typeof(Yahoo.us.ArtistSearchResponse.ResultSet));
res = (Yahoo.us.ArtistSearchResponse.ResultSet)
serializer.Deserialize(strm);
}
catch (Exception ex)
{
Label1.Text = "エラー:" + Server.HtmlEncode(ex.Message);
return;
}
finally
{
if (response != null)
response.Close();
}
Label1.Text = "";
if (res.totalResultsReturned == "0")
{
Label1.Text += "該当するアーティストが見つかりませんでした。";
}
else
{
Label1.Text += "<ul>\n";
foreach (Yahoo.us.ArtistSearchResponse.ResultType item in
res.Result)
{
Label1.Text += "<li>" + item.Name + "\n";
if (item.PopularSongs != null)
{
Label1.Text += "<ul>\n";
foreach (Yahoo.us.ArtistSearchResponse.SongType song in
item.PopularSongs)
{
Label1.Text += "<li>" + song.Value;
}
Label1.Text += "</ul>\n";
}
}
Label1.Text += "</ul>\n";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Yahoo! Search Web Services: Artist Search サンプル</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server"
OnClick="Button1_Click" Text="送信" /><br />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="False">
</asp:Label></div>
</form>
<!-- Begin Yahoo Web Services HTML Attribution Snippet -->
<a href="http://developer.yahoo.net/about/">
Web Services by Yahoo!
</a>
<!-- End Yahoo Web Services HTML Attribution Snippet -->
</body>
</html>
|
ページ情報 |
- 作成日 : 2006-09-12 (火) 02:13:12
- 作成者 : DOBON!
- 最終編集日 : 2006-09-12 (火) 02:34:24
- 最終編集者 : DOBON!
|