Use bo api to develop word query software.
Bo api is a free Data Service API (http://www.boapi.net/), its word query interface http://service.boapi.net/EnWord/EnWord.ashx? Key = AppKey & type = w & word = good, where AppKey is the applied key and word is the word to be queried. For more information, see http://www.boapi.net/enword.htm.
Development language: C # (wpf)
Tool: VS2012
Key code
1 private void btnSearch_Click(object sender, RoutedEventArgs e) 2 { 3 string word = tbKey.Text.Trim(); 4 if (word == "") 5 return; 6 try 7 { 8 WebClient wc = new WebClient(); 9 wc.Encoding = System.Text.Encoding.UTF8;10 string json = wc.DownloadString("http://service.boapi.net/EnWord/EnWord.ashx?appkey=298fc40c3be17b1b94e2f&word=" + word);11 wc.Dispose();12 if (!string.IsNullOrEmpty(json))13 {14 JToken jk = (JToken)JsonConvert.DeserializeObject(json);15 if (jk != null)16 {17 tbWord.Text = word;18 tbPhonetic.Text = "[" + jk["mark"].ToString() + "]";19 tbTrans.Text = jk["explain"].ToString();20 voice.Visibility = Visibility.Visible;21 voice.Tag = "http://www.boapi.net/basicdata/voice/" + word.Substring(0, 1) + "/" + jk["voice"].ToString();22 if (jk["es"] != null)23 {24 if (jk["es"].Count() > 0)25 tbSentence.Text = jk["es"][0]["sentence"].ToString() + " " + jk["es"][0]["translate"].ToString();26 if (jk["es"].Count() > 1)27 tbSentence.Text += Environment.NewLine + jk["es"][1]["sentence"].ToString() + " " + jk["es"][1]["translate"].ToString();28 //if (jk["es"].Count() > 2)29 // tbSentence.Text += Environment.NewLine + jk["es"][2]["sentence"].ToString() + " " + jk["es"][2]["translate"].ToString();30 }31 }32 }33 }34 catch35 { }36 }
Code parsing:
WebClient provides a public method for receiving data from resources. We can download data from a remote url (Access Service ).
JsonConvert. DeserializeObject deserializes string into a json object
Voice is a playback icon. The audio file address of a word is stored in the Tag attribute of voice.
Note:
In the json returned by a word query, Voice represents the name of the word speech file. The url for accessing the voice file is http://www.boapi.net/basicdata/voice/single-Word file name.
For example, to query "voice": "good.wav" in the json returned by good words, the url of good words is the http://www.boapi.net/basicdata/voice/good.wav
Source code download: Word search software source code