I have been trying to use Google Transliterate API using the RESTful approach as its easy to do so through server side language (C# here).
So, I came across this URL format: http://www.google.com/transliterate/indic?tlqt=1&langpair=en|hi&text=bharat%2Cindia&tl_app=3 which returns the JSON in the format:
[
{
"ew" : "bharat",
"hws" : [
"भारत","भरत","भरात","भारात","बहरत",
]
},
{
"ew" : "india",
"hws" : [
"इंडिया","इन्डिया","इण्डिया","ईन्डिया","इनडिया",
]
},
]
I tried HttpWebRequest
and HttpWebResponse
to get the JSON but it returned values in Unicode on the web browser, such as:
[ { "ew" : "bharat", "hws" : [ "\u092D\u093E\u0930\u0924","\u092D\u0930\u0924","\u092D\u0930\u093E\u0924","\u092D\u093E\u0930\u093E\u0924","\u092C\u0939\u0930\u0924", ] }, { "ew" : "india", "hws" : [ "\u0907\u0902\u0921\u093F\u092F\u093E","\u0907\u0928\u094D\u0921\u093F\u092F\u093E","\u0907\u0923\u094D\u0921\u093F\u092F\u093E","\u0908\u0928\u094D\u0921\u093F\u092F\u093E","\u0907\u0928\u0921\u093F\u092F\u093E", ] }, ]
So, I applied this article and passed the JSON string via it, and it returned:
[ { "ew" : "bharat", "hws" : [ "भारत","भरत","भरात","भारात","बहरत", ] }, { "ew" : "india", "hws" : [ "इंडिया","इन्डिया","इण्डिया","ईन्डिया","इनडिया", ] }, ]
FIRST QUESTION: Am I doing it right so far? Because in the browser it DOES NOT show the last " ] "
, however " ] "
exists in the HTML source (not sure why that happened). Also, when I try to parse it, using (I might be wrong using this technique):
var jss = new JavaScriptSerializer();
var dict = jss.Deserialize<Dictionary<string, dynamic>>(the_JSON_string);
Its giving me error saying:
Invalid array passed in, extra trailing ','.
SECOND QUESTION: If I am doing right so far, can I get some help parsing the Hindi words? What approach should I take using preferably System.Web.Script.Serialization;
. Eventually I want to grab the Hindi text for further processing.
Please help, thanks.