我试着下载这个地理编码数据

时间:2014-02-12 11:53:49

标签: objective-c google-maps url

基本上我正在访问此网址

http://maps.googleapis.com/maps/api/geocode/json?address=sudirman&sensor=true&bounds=-7.186696,105.7727|-5.186696,107.7727

但是,结果是空的。即使它应该显示一些东西。我用了objective-c

使用此代码:

response= [NSURLConnection sendSynchronousRequest:request returningResponse:&urlresponse error:&error];

json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];

我认为|需要进行urlencoded。怎么做?

1 个答案:

答案 0 :(得分:0)

[NSURLConnection sendSynchronousRequest:request returningResponse:&urlresponse error:&error];

返回NSData,序列化时会产生JSON,所以你需要这样做:

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingAllowFragments error:&error];

获取JSON。