OGeek|极客世界-中国程序员成长平台

标题: ios - AFNetworking 从 Google Geocode API 获取 json 不完整 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:34
标题: ios - AFNetworking 从 Google Geocode API 获取 json 不完整

是 AFNetworking 还是 googleapi 的 bug?我只得到部分 json 结果。如果我在 Chrome 上试用它,它工作正常。

   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

}];

返回 json,只包含我使用 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
                );
            },
                            {

使用 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" ]
                                             },
                                             {
                                                 "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"
 }



Best Answer-推荐答案


这可能只是打印数据时的 NSLog 限制。你可以看看这个question是否表明打印日志可能存在实际限制。最好的方法是按“ block ”打印它。结果是一个 JSONArray ,您可以在其中通过对象的循环打印日志(或仅打印必要的信息)。

关于ios - AFNetworking 从 Google Geocode API 获取 json 不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39582844/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4