2014-02-12 32 views
0

基本上我訪問這個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。如何做?

+0

可能的重複。請參閱[如何在JavaScript中編碼URL?](http://stackoverflow.com/questions/332872/how-to-encode-a-url-in-javascript) –

回答

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

NSData的回報,這連載時會產生JSON,所以你需要做的:

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

得到JSON。