iOS学习笔记(2):MiniDictionary
09 Aug 2012功能:使用API实现翻译。
API地址:http://api.liqwei.com/
- (IBAction)btnPress:(UIButton *)sender { if([_textField.text length]==0){ return; } NSStringEncoding encode=CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSString *strURL=[[NSString stringWithFormat:@"http://api.liqwei.com/translate/?language=zh-CN|en&content=%@",_textField.text]stringByAddingPercentEscapesUsingEncoding:encode]; NSURL *url=[NSURL URLWithString:strURL]; NSError *err=nil; NSString *strResult=[NSString stringWithContentsOfURL:url encoding:encode error:&err]; if(err){ NSLog(@"err=%@",[err description]); }else { _lblResult.text=strResult; } }
转载请注明:于哲的博客 » iOS学习笔记(2):MiniDictionary