public BingTrans Trans(string word, string fromLanguage, string toLanguage) { var tk = JavaScriptHandle.Instance.tk(word, "414398.1781904367"); string TransUrl = $"https://translate.google.com/translate_a/single?client=t&sl=auto&tl={toLanguage}&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&pc=1&ssel=0&tsel=0&kc=2&tk={tk}&q={word}"; var TransResultJson = string.Empty; try { var googleTransUrl = new StringBuilder(); TransResultJson = Sever.HttpGet(TransUrl, ""); string Aem = ""; string BrE = ""; var defs = new List <defs>(); try { var jarray = JArray.Parse(TransResultJson); if (jarray[1].Count() > 0) { foreach (var Item in jarray[1]) { defs.Add(new RecitingWord.defs() { def = Item[1].GetEnumeratorString(), pos = Item[0].ToString() }); } } else { defs.Add(new RecitingWord.defs() { def = jarray[0][0][0].ToString(), pos = string.Empty }); } } catch (Exception ex) { Console.WriteLine("json解析错误->{0},message = {1}", TransResultJson, ex.Message); BingTransApi.ErrorRecords("BulidBingTransError", string.Format("json = {0},message = {1}", TransResultJson, ex.Message)); } return(new BingTrans(word, Aem, BrE, defs)); } catch (Exception ex) { Console.WriteLine("服务器错误 -> {0}", ex.Message); } return(new BingTrans("", "", "", new List <defs>())); }
public static BingTrans BulidBingTrans(string Json) { string Word = ""; string Aem = ""; string BrE = ""; bool Exception = false; var defs = new List <defs>(); try { var json = JObject.Parse(Json); foreach (var item in json["items"]) { defs.Add(new defs() { def = item.Value <string>("text"), pos = "" }); } Exception = defs.Count == 0; //Word = json["word"].Value<string>(); //try //{ // Aem = json["pronunciation"].Value<string>("AmE"); // BrE = json["pronunciation"].Value<string>("BrE"); //} //catch (Exception) { } } catch (Exception ex) { //Console.WriteLine("json解析错误->{0},message = {1}", Json, ex.Message); BingTransApi.ErrorRecords("BulidBingTransError", string.Format("json = {0},message = {1}", Json, ex.Message)); Exception = true; } return(new BingTrans(Word, Aem, BrE, defs) { Error = Exception }); }