AFNetworking从Google Geocode API获取json是不完整的

时间:2016-09-19 22:07:56

标签: ios json google-maps google-geocoding-api afnetworking-3

这是AFNetworking或googleapi的错误吗?我只得到部分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"
 }

1 个答案:

答案 0 :(得分:0)

打印数据时,这可能只是 let cmTimeStart = CMTimeMake(0, 0) let cmTimeDuration = CMTimeMake(10, 1) let timeRange = CMTimeRange(start: cmTimeStart, duration: cmTimeDuration) let timedMetadataGroup = self.setupNavigationMarker(title: "test", description: "description test" , timeRange: timeRange) let timedMetadataGroupList = [timedMetadataGroup] let navigationMarkersGroup = AVNavigationMarkersGroup(title: "Chapters", timedNavigationMarkers: timedMetadataGroupList) //predefined avPlayerItem avPlayerItem.navigationMarkerGroups.append(navigationMarkersGroup) 限制。您可以查看此question,表明打印日志可能存在实际限制。对此最好的方法是用“块”打印它。结果是NSLog,您可以通过循环在对象上打印日志(或只打印必要的信息)。