jrsfiend22

ezb - google something!

Sep 27th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using Newtonsoft.Json.Linq;;
  2.  
  3. ...
  4.     private void button1_Click(object sender, EventArgs e) {
  5.         textBox1.AppendText("Searching 'Jarett Dunn'");
  6.                 textBox1.AppendText(Environment.NewLine);
  7.  
  8.         HttpWebRequest request = WebRequest.Create("https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Jarett%20Dunn") as HttpWebRequest;
  9.         using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  10.         {
  11.             StreamReader reader = new StreamReader(response.GetResponseStream());
  12.  
  13.             var json = reader.ReadLine();
  14.             var objects = JObject.Parse(json)["responseData"]["results"];  
  15.             for (int i = 0; i <= 3; i++)
  16.             {
  17.                 var title = objects[i]["titleNoFormatting"];
  18.                 var content = objects[i]["content"];
  19.  
  20.                 textBox1.AppendText("Result #: " + i.ToString());
  21.                 textBox1.AppendText(Environment.NewLine);
  22.                 textBox1.AppendText(Environment.NewLine);
  23.                 textBox1.AppendText("Title: " + title.ToString());
  24.                 textBox1.AppendText(Environment.NewLine);
  25.                 textBox1.AppendText("Contents: " + content.ToString());
  26.                 textBox1.AppendText(Environment.NewLine);
  27.                 textBox1.AppendText(Environment.NewLine);
  28.                 textBox1.AppendText(Environment.NewLine);
  29.             }
  30.         }  
  31.     }
Add Comment
Please, Sign In to add comment