国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

漢語(yǔ)字典或者詞典的簡(jiǎn)單的ios小demo

2019-11-14 18:43:36
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

[注意]轉(zhuǎn)載時(shí)請(qǐng)注明出處博客園-吃唐僧肉的小悟空http://m.survivalescaperooms.com/hukezhu/

 

首先感謝  枯龍吟  網(wǎng)易博客提供了【成語(yǔ)詞典】【新華字典】【漢語(yǔ)詞典】接口以供使用.

無(wú)意中在網(wǎng)上發(fā)現(xiàn)了一個(gè)關(guān)于漢語(yǔ)字典方面的接口 ,于是自己就測(cè)試了一下,發(fā)現(xiàn)可以使用,非常感謝那位大神!!!

附上demo截圖:

 

主要用到了數(shù)據(jù)解析的方式,服務(wù)器返回的是json數(shù)據(jù),直接使用ios提供的類進(jìn)行解析,這個(gè)小demo很簡(jiǎn)單,直接附上源碼:(代碼中,我封裝了一個(gè)方法,傳入服務(wù)器的地址和請(qǐng)求的數(shù)據(jù),回到主線程更新UI)

  1 //  2 //  ViewController.m  3 //  新華字典  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(@"點(diǎn)擊了查找按鈕"); 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     //這個(gè)是周公解夢(mèng)的,可是api不能使用了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

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 玛沁县| 张家港市| 许昌县| 双柏县| 商丘市| 格尔木市| 莎车县| 德令哈市| 开江县| 太谷县| 宜都市| 闽侯县| 静海县| 徐汇区| 济阳县| 商城县| 镇平县| 运城市| 白朗县| 达尔| 错那县| 合肥市| 榆林市| 九龙坡区| 重庆市| 东丰县| 措美县| 桃园县| 奉贤区| 樟树市| 大厂| 札达县| 兴业县| 萨迦县| 岳阳县| 鄄城县| 鹿泉市| 新沂市| 安阳市| 永德县| 昌图县|