【发布时间】:2015-05-07 21:26:48
【问题描述】:
我正在尝试使用以下代码从 google 地方获取 json:
NSString *query = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%i&types=%@&sensor=true&key=%@", center.latitude, center.longitude, rad, types, kGOOGLE_API_KEY];
NSLog(@"%@",query);
NSURL *googleRequestURL=[NSURL URLWithString:query];
[NSURLConnection sendAsynchronousRequest:[[NSURLRequest alloc] initWithURL:googleRequestURL] queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(@"Error fetching data: %@",[error description]);
} else {
//To-do
}
}];
(我的密钥由于某些原因被省略了)
在我的笔记本电脑浏览器上运行良好,但返回错误:
Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo=0x7fe47bc138f0 {NSLocalizedDescription=unsupported URL, NSUnderlyingError=0x7fe47be9dbe0 "unsupported URL"}
我尝试使用http而不是https(在浏览器中它返回一个带有一些错误消息的json,但仍然返回一些东西)没有成功。
我做错了什么?
【问题讨论】:
标签: ios8 nsurl nsurlrequest