Public stringAppID ="their own appid."; Public stringQ ="the text to translate"; Public stringSalt ="1435660288"; Public stringKey ="your secret key."; Public string from="your source language, such as zh"; Public stringto ="languages to be translated such as En"; Public stringGetjson () {varClient =NewRestclient ("http://api.fanyi.baidu.com"); varRequest =NewRestrequest ("/api/trans/vip/translate", Method.get); Request. Addparameter ("Q", q); Request. Addparameter (" from", from); Request. Addparameter (" to", to); Request. Addparameter ("AppID", AppID); Request. Addparameter ("Salt", salt); Request. Addparameter (" Sign", GetMd5 ()); Irestresponse Response=client. Execute (Request); returnResponse. Content; } Public stringSign {Get{return string. Format ("{0}{1}{2}{3}", AppID, Q, salt, key); } } stringGetMd5 () {varMD5 =NewMD5CryptoServiceProvider (); varresult =Encoding.UTF8.GetBytes (sign); varOutput =Md5.computehash (Result); returnBitconverter.tostring (Output). Replace ("-",""). ToLower (); } Private voidButton1_Click (Objectsender, EventArgs e) {TextBox2.Text=GetResult (); } Public stringGetResult () {varLST =Newlist<string>(); varContent =Getjson (); DynamicJSON =jsonconvert.deserializeobject (content); foreach(varIteminchJson.trans_result) {lst. ADD (Item.dst.ToString ()); } return string. Join (";", LST); }
To reference Newtonsoft.Json.dll
Https://download.csdn.net/download/jsqdragoon/10032906?web=web
Call Baidu Translator API interface function