Using the following snippet of code, I can get 4 results from the google Web Search API. I know I’m using a deprecated API, but I’m only testing something here and will use the new Custom Search API when I’m more familiar with it. For now, though, I was wondering how I can parse the returned result for the “unescapedUrl” that is in the result? Basically, I want to grab all four of the “unescapedUrl” values in the returned JSON.
Here’s my code:
var searchTerm = "pizza boxes";
using (var web = new WebClient())
{
web.Headers.Add("Referrer", "http://localhost:49360/");
var result = web.DownloadString(String.Format(
"http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q={0}&rsz=4",
searchTerm));
Console.WriteLine(result);
}
I don’t want to use JSON.Net with this (for now) unless I absolutely have to. Any ideas?
Thanks!
You’d need to create a type, but have you thought about using JavaScriptSerializer from System.Web.Extensions.dll?
I can’t say I know the Google API well, but if it’s a simple JSON property bag that’s returned, you could get away with something as simple as this: