A simple ios demo of a Chinese dictionary or dictionary, and an iosdemo of a Chinese Dictionary

Source: Internet
Author: User

A simple ios demo of a Chinese dictionary or dictionary, and an iosdemo of a Chinese Dictionary

[Note] reprinted, please indicate the source of blog Park-eat Tang sick Wukong http://www.cnblogs.com/hukezhu/

 

First of all, I would like to express my appreciation for the [idiom dictionary] [Xinhua Dictionary] [Chinese Dictionary] interface provided by the Netease blog for use.

I accidentally found an interface for Chinese dictionary on the Internet, so I tested it and found it usable. Thank you very much !!!

Attached demo:

 

It mainly uses the data parsing method. The server returns json data and directly uses the classes provided by ios for parsing. This small demo is very simple and directly attaches the source code: (in the code, I encapsulated a method to pass in the server address and request data and return to the main thread to update the UI)

1 // 2 // ViewController. m 3 // Xinhua Dictionary 4 // 5 // Created by hukezhu on 15/7/7. 6 // Copyright (c) 2015 hukezhu. all rights reserved. 7 // 8 9 # import "ViewController. h "10 # import <AFNetworking. h> 11 12 @ interface ViewController () 13 @ property (weak, nonatomic) IBOutlet UITextField * word; 14 @ property (weak, nonatomic) IBOutlet UITextField * chengyu; 15 @ property (weak, nonatomic) IBOutlet UITextView * textView; 16 @ property (weak, nonatomic) IBOutlet UITextField * ciyu; 17 18-(IBAction) wordClick :( UIButton *) sender; 19-(IBAction) chengyuClick :( UIButton *) sender; 20-(IBAction) ciyuClick :( UIButton *) sender; 21 22 @ end 23 24 @ implementation ViewController 25 26 27 28 29-(void) viewDidLoad {30 [super viewDidLoad]; 31 32} 33 34 35-(void) getDictionary :( NSString *) strUrl word :( NSString *) word {36 37 NSString * stringUrl = strUrl; 38 AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager manager]; 39 manager. responseSerializer. acceptableContentTypes = [NSSet setWithObjects: @ "application/json", @ "text/json", @ "text/javascript", @ "text/html", nil]; 40 41 [manager GET: stringUrl parameters: @ {@ "word": word} success: ^ (AFHTTPRequestOperation * operation, id json) {42 43 NSData * data = [NSJSONSerialization dataWithJSONObject: json options: 0 error: NULL]; 44 45 46 NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: data options: 0 error: NULL]; 47 48 49 50 NSString * rootKey = dict. keyEnumerator. nextObject; 51 NSArray * array = dict [rootKey]; 52 53 54 55 NSMutableString * stringM = [NSMutableString string]; 56 for (NSDictionary * dict1 in array) {57 58 for (NSString * key in dict1) {59 if ([key isEqualToString: @ "text"]) {60 NSString * object = [dict1 objectForKey: key]; 61 // NSLog (@ "% @", object); 62 [stringM appendFormat: @ "% @ \ n", object]; 63} 64 65} 66} 67 68 self. textView. text = stringM; 69} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {70 NSLog (@ "error: % @", error); 71}]; 72 73 74} 75 76-(IBAction) wordClick :( UIButton *) sender {77 78 // NSLog (@ "click the search button"); 79 if (self. word. text) {80 [self getDictionary: @ "http://brisk.eu.org/api/xhzd.php" word: self. word. text]; 81} 82 83 [self. view endEditing: YES]; 84 85 86} 87 88-(IBAction) chengyuClick :( UIButton *) sender {89 90 if (self. chengyu. text) {91 [self getDictionary: @ "http://brisk.eu.org/api/cycd.php" word: self. chengyu. text]; 92} 93 94 [self. view endEditing: YES]; 95} 96 97-(IBAction) ciyuClick :( UIButton *) sender {98 99 if (self. ciyu. text) {100 [self getDictionary: @ "http://brisk.eu.org/api/hycd.php" word: self. ciyu. text]; 101} 102 103 104 // This is the solution of Zhou's public dream, but the api cannot use 105 // if (self. ciyu. text) {106 // [self getDictionary: @ "http://brisk.eu.org/api/dream.php" word: self. ciyu. text]; 107 //} 108 109 [self. view endEditing: YES]; 110} 111 @ end

 

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.