And now the same code in C#:
WebRequest request = WebRequest.Create(”http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=%7Cit”);
// This command performs a Language Translation(/ajax/services/language/translate), for Hello World (q=hello%20world)
// from English to Italian (langpair=en%7Cit). i.e. en|it . Or you can leave the source language blank if you want auto-detection & translation.
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string json = reader.ReadLine();
JsonObject account;
JsonObject responseData;
JsonString responseDetails;
JsonNumber responseStatus;
using (JsonParser parser = new JsonParser(new StringReader(json), true))
account = parser.ParseObject();
//responseDetails = (JsonString)account["responseDetails"];
responseStatus = (JsonNumber)account["responseStatus"];
responseData = (JsonObject)account["responseData"];
Console.WriteLine(”responseStatus: {0}”, responseStatus.Value);
Console.WriteLine(”translatedText: {0}”, responseData["translatedText"]);
Console.WriteLine(”detectedSourceLanguage: {0}”, responseData["detectedSourceLanguage"]);
// You can get the JSON .NET 2.0 parser I use from here.
// Or if you have .NET 3.5 you can use DataContractJsonSerializer to serializes objects to the JavaScript Object Notation (JSON) and deserializes JSON data to objects.