JSON解析谷歌翻译API

时间:2014-07-19 21:36:58

标签: ios google-app-engine

我正在尝试解析谷歌翻译的数据。在viewdidload中,我编写了以下代码。

NSString * target = @"ja";
NSString * source = @"en";
NSString *textEscaped = @"Hi, How are u";
NSString *ke=@"My_key";
NSString * urlText =[NSString 
key=%@&source=%@&format=text&target=%@&q=%@",ke,source,target,textEscaped];
NSURL *url = [NSURL URLWithString:urlText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"GET"];

NSURLResponse *response;
NSError *error;

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response 
error:&error];

NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"%@",result);

我将我的代码与不同的源进行比较,我的API也被激活,但我在结果字符串中没有得到任何结果。它的法案。为什么呢?

1 个答案:

答案 0 :(得分:0)

像这样创建您的网址:

[NSString  stringWithFormat:@"https://www.googleapis.com/language/translate/v2key=%@&target=%@&q=%@",key, target, selectedWord];