學習ios開發系列之,利用百度詞典api寫的ios詞典app,iosapp

來源:互聯網
上載者:User

學習ios開發系列之,利用百度詞典api寫的ios詞典app,iosapp

先附上:

  

還是很簡單,主要用的storyboard,不過準備學習下cocoui來布局了,storyboard很逆天! 其他的就是http請求這塊,還有NSString類使用了! 

   附上主要的原始碼:

  

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;

已經想不起來這是第幾個詞典小工具了!再準備寫一個天氣查詢的功能

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.