这是我的代码:
NSString *url = @"https://www.googleapis.com/language/translate/v2?key=API&q=hello%20world&source=en&target=de";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSLog(@"%@",request);
NSData *response = [NSURLConnection sendSynchronousRequest:request
returningResponse:nil
error:nil];
NSLog(@"%@",response);
NSError *jsonParsingError = nil;
NSArray *retrievedJTrans = [NSJSONSerialization JSONObjectWithData:response options:0 error:&jsonParsingError];
NSLog(@"%@",retrievedJTrans);
NSDictionary *translation;
for(int i=0; i<[retrievedJTrans count];i++)
{
translation=[retrievedJTrans objectAtIndex:i];
NSLog(@"Statuses: %@", [translation objectForKey:@"translatedText"]);
}
NSLog(@"%@",[translation class]);
我正在尝试从这个简单的 JSON 中检索翻译后的文本:
{
"data": {
"translations": [
{
"translatedText": "Hallo Welt"
}
]
}
}
但我收到错误:
-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance
任何帮助表示赞赏。使用最新的 Xcode。