iOS アプリケーションを使用して中国語を翻訳しようとしています。「Google Translate API」を使用すると、翻訳にエラーが発生しますが、同じテキストを使用すると、Google 翻訳の Web ページでは翻訳にエラーが発生しません。「Google 翻訳」API の応答には、「"」と「'」の文字も含まれます。以下は、それに関連するコード スニペットです。
//Text recognized by tesseract.
text = [recText stringByAddingPercentEncodingWithAllowedCharacters:set];
NSString * urlText =[NSString stringWithFormat:@"https://www.googleapis.com/language/translate/v2?key=%@&source=%@&target=%@&q=%@",_key,_sourceLanguage,_targetLanguage,text];
NSURL *url = [NSURL URLWithString:urlText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
NSError *error;
[request setURL:url];
[request setHTTPMethod:@"GET"];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
if(response != nil)
{
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:response options:kNilOptions error:&error];
NSDictionary *data = dic[@"data"];
NSArray *translations = data[@"translations"];
for (NSDictionary *translation in translations)
{
translatedText = translation[@"translatedText"];
}
}