public void Search_songs() { song_info.Text = ""; string search_text = songdata.Value; string url = "https://itunes.apple.com/search?term=" + search_text; Uri uri = new Uri(@url); WebRequest webRequest = WebRequest.Create(uri); WebResponse response = webRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); String responseData = streamReader.ReadToEnd(); Songcollection resultCount = JsonConvert.DeserializeObject <Songcollection>(responseData); int Result_count_song = resultCount.Results.Count; if (Result_count_song < 1) { song_info.Text = "<p>No search results found for <strong>" + search_text + "</strong>. This song seems to be not so famous. Time to improve your taste perhaps <img src=\"images/smiley.jpg\" alt=\":P\" height=\"20\" width=\"20\" /> </p>"; } else { int i = 1; foreach (var data in resultCount.Results) { song_info.Text += i + ". " + "<strong>Artist Name:</strong>" + data.ArtistName + "<br/><strong>Collection Name:</strong>" + "" + data.CollectionName + " <br/><strong>Track Name:</strong>" + data.TrackName + "<br/><strong>Primary Genre Name:</strong>" + data.PrimaryGenreName + "<br/><strong>Preview URL:</strong> <a href=\"" + data.PreviewUrl + "\">Click here for song Preview</a> <br/>"; i++; } } }
protected void Page_Load(object sender, EventArgs e) { //This funtion will be called when user types atleast two characters in the song search box. //It will fetch and display all the songs containing the searched characters to give suggestions to users. String term = Request.QueryString["term"]; // get the letters that the user typed Response.Clear(); // change the content type, so the browser knows it's JSON Response.ContentType = "application/json; charset=utf-8"; using (var webClient = new WebClient()) { string search_text = term; string url = "https://itunes.apple.com/search?term=" + search_text; Uri uri = new Uri(@url); WebRequest webRequest = WebRequest.Create(uri); WebResponse response = webRequest.GetResponse(); StreamReader streamReader = new StreamReader(response.GetResponseStream()); String responseData = streamReader.ReadToEnd(); Songcollection resultCount = JsonConvert.DeserializeObject <Songcollection>(responseData); List <String> matchedinfosong = new List <String>(); if (term != null && term.Length > 0) { foreach (var resultObj in resultCount.Results) { if (!string.IsNullOrEmpty(resultObj.TrackName) && resultObj.TrackName.ToUpper().Contains(term.ToUpper())) { matchedinfosong.Add(resultObj.TrackName); } } } string matchedJson = JsonConvert.SerializeObject(matchedinfosong); Response.Write(matchedJson); } Response.End(); }