NSURL *URL = [NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=true&key=AIzaSyDbiWWIOmc08YSb9DAkdyTWXh_PirVuXpM"];
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:URL];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
But in did finish loading delegate method i cant get the data.That code is here.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc]initWithData:responseDataencoding:NSUTF8StringEncoding];
[responseData release];
SBJSON *parser = [[SBJSON alloc]init];
NSDictionary *data = (NSDictionary *) [parser objectWithString:responseString error:nil];
}
所以请告诉我我在哪里犯了错误。为什么我没有得到数据。
答案 0 :(得分:0)
根据我的知识,很少有错误。
NSString *responseString = [[NSString alloc]initWithData:responseDataencoding:NSUTF8StringEncoding];
单词 responseData encoding 是两个世界。我不知道你是否粘贴过这样的东西。
我希望您使用-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
个委托将数据附加到responseData对象。
我认为您不需要转换为NSDictionary。您可以使用以下代码。
NSString *content = [[NSString alloc] initWithBytes:[responseDate bytes] length:[responseDate length] encoding:NSUTF8StringEncoding];
NSLog(@"Data = %@", content);
NSError *error;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *jsonD = [parser objectWithString:content error:&error];
答案 1 :(得分:0)