Use the BO API to develop word-search small software

Source: Internet
Author: User

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 application of the Key,word is the queried word. See http://www.boapi.net/enword.htm for detailed documentation.

Development language: C # (WPF)

Tool: VS2012

Key code

1 Private voidbtnSearch_Click (Objectsender, RoutedEventArgs e)2 {3       stringWord =TbKey.Text.Trim ();4       if(Word = ="")5          return;6       Try7       {8WebClient WC =NewWebClient ();9Wc. Encoding =System.Text.Encoding.UTF8;Ten           stringJSON = WC. Downloadstring ("http://service.boapi.net/EnWord/EnWord.ashx?appkey=298fc40c3be17b1b94e2f&word="+word); One WC. Dispose (); A           if(!string. IsNullOrEmpty (JSON)) -           { -Jtoken JK =(Jtoken) jsonconvert.deserializeobject (JSON); the                if(JK! =NULL) -                { -Tbword.text =Word; -Tbphonetic.text ="["+ jk["Mark"]. ToString () +"]"; +Tbtrans.text = jk["explain"]. ToString (); -Voice. Visibility =visibility.visible; +Voice. Tag ="http://www.boapi.net/basicdata/voice/"+ Word. Substring (0,1) +"/"+ jk["Voice"]. ToString (); A                    if(jk["es"] !=NULL) at                    { -                        if(jk["es"]. Count () >0) -Tbsentence.text = jk["es"][0]["sentence"]. ToString () +" "+ jk["es"][0]["Translate"]. ToString (); -                        if(jk["es"]. Count () >1) -Tbsentence.text + = Environment.NewLine + jk["es"][1]["sentence"]. ToString () +" "+ jk["es"][1]["Translate"]. ToString (); -                        //if (jk["es"). Count () > 2) in                        //Tbsentence.text + = Environment.NewLine + jk["es"][2]["sentence"]. ToString () + "" + jk["es"][2]["translate"]. ToString (); -                    } to                } +            } -       } the       Catch *       { } $}

Code parsing:

WebClient provides a public way to receive data from the resource, we can download the data from the remote URL address (access the service).
Jsonconvert.deserializeobject to deserialize a string into a JSON object
Voice is a play icon, where the audio file address of a word is stored in the Voice's Tag property

Attention:

In the JSON returned by the word query, voice represents the word voice file name. The URL of the Access speech file is: http://www.boapi.net/basicdata/voice/word filename

such as: Query good word returned in the JSON "Voice": "Good.wav", the good word URL is http://www.boapi.net/basicdata/voice/good.wav

Source code Download: Word Query software source code

Use the BO API to develop word-search small software

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.