Learning the ios development series, using the ios dictionary app and iosapp written by Baidu dictionary api

Source: Internet
Author: User

Learning the ios development series, using the ios dictionary app and iosapp written by Baidu dictionary api

Attached first:

  

It is still very simple. storyboard is mainly used, but it is ready to be learned to layout cocoui. storyboard is very backward! The other is the http request, and the NSString class is used!

The main source code is attached:

  

NSString* queryword = word.text;        NSString* urlStr = [[NSString alloc] initWithFormat:@"http://openapi.baidu.com/public/2.0/translate/dict/simple?client_id=5kHZHeo8MN7L6NmPTGV6POsb&q=%s&from=en&to=zh",queryword.UTF8String];            NSURL* url = [NSURL URLWithString:urlStr];                NSURLRequest* request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];        NSHTTPURLResponse* response = nil;    NSData* returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];        NSString* resultData = [[NSString alloc] init];        NSError* error;        NSDictionary* json = [NSJSONSerialization JSONObjectWithData:returnData options:kNilOptions error:&error];        NSDictionary* data = [json objectForKey:@"data"];        NSArray* symbols = [data objectForKey:@"symbols"];        for(int i=0;i<symbols.count;i++)    {                NSDictionary* item = [symbols objectAtIndex:i];        NSArray* temp = [item objectForKey:@"parts"];                for (int k = 0; k< temp.count;k++)        {            NSDictionary* subItem = [temp objectAtIndex:k];                        resultData = [resultData stringByAppendingString:[subItem objectForKey:@"part"]];                    NSArray* arr = [subItem objectForKey:@"means"];                    for(int j=0;j<arr.count;j++)            {                resultData = [resultData stringByAppendingString:[arr objectAtIndex:j]];            }        }    }            result.text = resultData;

I cannot remember the first few dictionary gadgets! Prepare a weather query function.

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.