【发布时间】:2013-07-31 02:24:49
【问题描述】:
我看过一些使用谷歌翻译网页的帖子。
NSString* englishString = [englishInputArray objectAtIndex:i];
NSString *urlPath = [NSString stringWithFormat:@"/translate_a/t?client=t&text=%@&langpair=en|fr",englishString];
NSURL *url = [[NSURL alloc] initWithScheme:@"http" host:@"translate.google.com" path:urlPath];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"GET"];
NSURLResponse *response;
NSError *error;
NSData *data;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *result = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(@"Text: %@",result);
我有两个问题: 1)从网页返回的json是这样的
[[["Bonjour","Hello","",""]],[["interjection",["bonjour","salut","all\u00f4","tiens"]]],"en",,[["Bonjour",[5],1,0,1000,0,1,0]],[["Hello",4,,,""],["Hello",5,[["Bonjour",1000,1,0]],[[0,5]],"Hello"]],,,[],1]
除了进行字符串操作之外,还有一种方法可以单独获取确切的翻译字符串,即在这种情况下单独获取“Bonjour”。
2: 有人知道这是否是免费服务吗? Google apis 似乎是一项付费服务。但如果你使用网页是一项免费服务。
【问题讨论】:
-
1.你知道“解析”和
NSJSONSerialization类的概念吗? 2. 不,这是一项付费服务,如果您想将其用作 API。但是,如果您只访问该网站,那是免费的。 -
感谢您的回复。但关于第二部分再次有点困惑。因此,如果我以我在示例中显示的代码片段中使用的方式使用 google servive,那么这看起来不像付费服务。[它不是 api]。所以它应该是免费服务?
-
嗯,它看起来就像一个 API,据我所知,它是付费的。但你知道的......
-
根据这篇文章:stackoverflow.com/questions/8085743/... 谷歌翻译是免费的,但谷歌 API 是付费服务。但可能当谷歌看到大量使用翻译网页来自特定网站时,他们可能会阻止该特定 IP。
标签: objective-c cocoa-touch google-translate