iphone - 翻译错误

标签 iphone objective-c

NSString *soundURL = [NSString stringWithFormat:@"http://translate.google.com/translate_tts?q=%@&tl=%@",strTextOfFilter,strCodeOfLanguage];
        NSLog(@"URL : %@",soundURL); 

这个节目:http://translate.google.com/translate_tts?q=%E4%BD%A0%E5%A5%BD&tl=zh-TW

复制url到firefox浏览器。中文翻译是对的,但是到safari的浏览器,就错了!为什么翻译中文是错误的。其他语言是正确的! 请帮助我!!!

    NSData *soundData = [NSData dataWithContentsOfURL:[NSURL URLWithString:soundURL]];
    NSLog(@"returnSoundData:%@",[NSURL URLWithString:soundURL]);
    NSError *err = nil;
    AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithData:soundData error: &err];
    [player play];

最佳答案

只需将 &ie=UTF-8 显式地放在 URL 的末尾,无论是在 Safari 中还是在您的代码中。

http://translate.google.com/translate_tts?q=%E4%BD%A0%E5%A5%BD&tl=zh-TW&ie=UTF-8

完成任务。我猜 Google 服务器对使用的编码感到困惑。

关于iphone - 翻译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3663934/

相关文章:

objective-c - 什么时候应该在 Objective-C 中使用 nil 和 NULL?

objective-c - 此类不符合键值编码

iphone - 如何在 iPhone 中添加左右对齐(两者)的单元格详细信息文本?

iphone - 在 iPhone 应用程序中保存数据并下次读取数据的最快方法是什么?

iphone - 在 UIWebView 中使用本地 CSS 文件

ios - Xcode Image Assets 为视网膜设备返回错误的图像

ios - 发布本地通知时应用程序崩溃

iphone - 检查互联网连接以及连接类型?

ios - 如何在 Objective-C 项目中遵循 Swift 库中制定的协议(protocol)

ios - mkannotation 中的自定义数据变量