简体   繁体   中英

AFNetworking get json from Google Geocode API is incomplete

Is it a bug of AFNetworking or googleapi? I only get partial json result. And if I try it on Chrome, it works fine.

   NSString *urlstring = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:\"%@\"", zipcodefield.text];
urlstring = [urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager.responseSerializer setAcceptableContentTypes:[NSSet setWithArray:@[@"application/json"]]];
[manager GET:urlstring parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
    NSDictionary *zipfile = (NSDictionary *)responseObject;
    NSLog(@"%@", zipfile);
} failure:^(NSURLSessionTask *operation, NSError *error) {
    //some code

}];

returns json with only part of the result the I got with Chrome:

{
results =     (
            {
        "address_components" =             (
                            {
                "long_name" = "N2L 3W6";
                "short_name" = "N2L 3W6";
                types =                     (
                    "postal_code"
                );
            },
                            {
                "long_name" = Waterloo;
                "short_name" = Waterloo;
                types =                     (
                    locality,
                    political
                );
            },
                            {
                "long_name" = "Waterloo Regional Municipality";
                "short_name" = "Waterloo Regional Municipality";
                types =                     (
                    "administrative_area_level_2",
                    political
                );
            },
                            {

with Chrome, it returns a different full result:

{
    "results" : [
                 {
                     "address_components" : [
                                             {
                                                 "long_name" : "N2L 3W6",
                                                 "short_name" : "N2L 3W6",
                                                 "types" : [ "postal_code" ]
                                             },
                                             {
                                                 "long_name" : "Waterloo",
                                                 "short_name" : "Waterloo",
                                                 "types" : [ "locality", "political" ]
                                             },
                                             {
                                                 "long_name" : "Waterloo Regional Municipality",
                                                 "short_name" : "Waterloo Regional Municipality",
                                                 "types" : [ "administrative_area_level_2", "political" ]
                                             },
                                             {
                                                 "long_name" : "Ontario",
                                                 "short_name" : "ON",
                                                 "types" : [ "administrative_area_level_1", "political" ]
                                             },
                                             {
                                                 "long_name" : "Canada",
                                                 "short_name" : "CA",
                                                 "types" : [ "country", "political" ]
                                             }
                                             ],
                     "formatted_address" : "Waterloo, ON N2L 3W6, Canada",
                     "geometry" : {
                         "bounds" : {
                             "northeast" : {
                                 "lat" : 43.4774664,
                                 "lng" : -80.53395789999999
                             },
                             "southwest" : {
                                 "lat" : 43.47248219999999,
                                 "lng" : -80.538017
                             }
                         },
                         "location" : {
                             "lat" : 43.473585,
                             "lng" : -80.5351634
                         },
                         "location_type" : "APPROXIMATE",
                         "viewport" : {
                             "northeast" : {
                                 "lat" : 43.4774664,
                                 "lng" : -80.53395789999999
                             },
                             "southwest" : {
                                 "lat" : 43.47248219999999,
                                 "lng" : -80.538017
                             }
                         }
                     },
                     "place_id" : "ChIJXV6ZhAf0K4gRYW7aCuG25xQ",
                     "types" : [ "postal_code" ]
                 }
                 ],
    "status" : "OK"
 }

This may just be the NSLog limitation when printing the data. You can check out this question were its indicated that there may be practical limitations on printing logs. The best approach for this is to print it by "chunks". The result is a JSONArray to in which you can just print logs thru a loop on the objects (or just print the necessary information).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM