Use bo api to develop word query software.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.