Puede utilizar Json.Net biblioteca y esta extension class que hace uso de DynamicObject
Algunos ejemplos de uso:
public static void GoogleGeoCode(string address)
{
string url = "http://maps.googleapis.com/maps/api/geocode/json?sensor=true&address=";
dynamic googleResults = new Uri(url + address).GetDynamicJsonObject();
foreach (var result in googleResults.results)
{
Console.WriteLine("[" + result.geometry.location.lat + "," +
result.geometry.location.lng + "] " +
result.formatted_address);
}
}
public static void GoogleSearch(string keyword)
{
string url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=8&q=";
dynamic googleResults = new Uri(url + keyword).GetDynamicJsonObject();
foreach (var result in googleResults.responseData.results)
{
Console.WriteLine(
result.titleNoFormatting + "\n" +
result.content + "\n" +
result.unescapedUrl + "\n");
}
}
public static void Twitter(string screenName)
{
string url = "https://api.twitter.com/1/users/lookup.json?screen_name=" + screenName;
dynamic result = new Uri(url).GetDynamicJsonObject();
foreach (var entry in result)
{
Console.WriteLine(entry.name + " " + entry.status.created_at);
}
}
public static void Wikipedia(string query)
{
string url = "http://en.wikipedia.org/w/api.php?action=opensearch&search=" + query +"&format=json";
dynamic result = new Uri(url).GetDynamicJsonObject();
Console.WriteLine("QUESTION: " + result[0]);
foreach (var entry in result[1])
{
Console.WriteLine("ANSWER: " + entry);
}
}
EDIT:
Aquí es otra muestra sin DynamicObject
public static void GoogleSearch2(string keyword)
{
string url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=8&q="+keyword;
using(WebClient wc = new WebClient())
{
wc.Encoding = System.Text.Encoding.UTF8;
wc.Headers["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E)";
string jsonStr = wc.DownloadString(url);
JObject jObject = (JObject)JsonConvert.DeserializeObject(jsonStr);
foreach (JObject result in jObject["responseData"]["results"])
{
Console.WriteLine(
result["titleNoFormatting"] + "\n" +
result["content"] + "\n" +
result["unescapedUrl"] + "\n");
}
}
}
Algunos blogs muestran cómo hacerlo usando WCF https://encrypted.google.com/search?q=wcf+rest+json – oleksii
@oleksii La mayoría de los enlaces detallan cómo crear un servicio que entregue JSON. Necesito una biblioteca para consumirla fácilmente. – AngryHacker