Это анализатор для переводов Google.Я перешел с api v1 на api v2 (платно), но у меня проблема.Перевод выполняется в журнале, но responseStatus равен 0, а не 200. Вы можете просмотреть журнал, перевод завершен.На странице Google, сказанное в json, также должно появиться вверху «200 OK», но оно не появится.Идеи?
-(void)getText:(NSString *)text lan1:(NSString *)lan1 lan2:(NSString *)lan2 {
translate = [[NSString stringWithString:text] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
lanTranslate = [[NSString stringWithString:lan1] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
lanTranslated = [[NSString stringWithString:lan2] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[self performTranslation];
}
-(void)performTranslation {
responseData = [NSMutableData data];
NSString *_translation = [NSString stringWithFormat:@"%@&target=%@", lanTranslate,lanTranslated];
NSString *translation = [_translation stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/language/translate/v2?key=MYKEY&source=%@&q=%@",translation, translate];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLConnection *go = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[go start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSMutableDictionary *JSONDictionary = [responseString JSONValue];
NSLog(@"res %@ js%@",responseString, JSONDictionary);
if (JSONDictionary != nil)
{
NSDecimalNumber * responseStatus = [JSONDictionary objectForKey:@"responseStatus"];
if ([responseStatus intValue] != 200) {
**NSLog(@"responseStatus %i",(int)responseStatus);**
return;
}
NSMutableDictionary *responseDataDict = [JSONDictionary objectForKey:@"responseData"];
if (responseDataDict != nil) {
NSString *translatedText = [responseDataDict objectForKey:@"translatedText"];
translated = [NSString stringWithString:translatedText];
[viewSuperiore translate:translated];
}
}
}
log
res {
"data": {
"translations": [
{
"translatedText": "text to be translated"
}
]
}
}
js{
data = {
translations = (
{
translatedText = "text to be translated";
}
);
};
}