我正在构建一个使用 google places api 的应用程序,我使用这个 url
当我在浏览器中使用所需的链接时,它不会产生任何结果
我使用 json 来解析来自 google 地方的数据,但我收到了这个不寻常的警告,它说 NSString 可能无法响应 JSONValue
代码如下
-(IBAction)nearbyLocations:(id)sender
{
NSString *url=[NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=37.329558,122.025002&radius=500&types=atm&sensor=false&key=AIzaSyCIZ8MxCoMsfgj0ytE7azXGfjs_E__2Nhw"];
NSURL *googleRequestURL=[NSURL URLWithString:url];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL: googleRequestURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData *)responseData
{
//parse out the json data
//NSError* error;
NSString *jsonString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@",jsonString);
NSDictionary* json =[jsonString JSONValue];
//[NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
//The results from Google will be an array obtained from the NSDictionary object with the key "results".
NSArray* places = [json objectForKey:@"results"];
//Write out the data to the console.
NSLog(@"Google Data: %@", places);
}