gpt4 book ai didi

ios - RestKit 警告 - 警告 : Failed mapping nested object: (null)

转载 作者:行者123 更新时间:2023-11-28 17:37:26 27 4
gpt4 key购买 nike

我刚开始学习 RestKit。我正在尝试使用它来使用 Foursquare api 获取附近的 field 。但每次我尝试“objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects”时,我都会收到此警告“警告:映射嵌套对象失败:(null)”。

我真的很困惑。以下是我在 init 方法中的映射代码:

 _objectManager = [RKObjectManager objectManagerWithBaseURL:@"https://api.foursquare.com"];

RKObjectMapping *locationMapping = [RKObjectMapping mappingForClass:[Location class]];
[locationMapping mapKeyPath:@"address" toAttribute:@"address"];
[locationMapping mapKeyPath:@"city" toAttribute:@"city"];
[locationMapping mapKeyPath:@"state" toAttribute:@"state"];
[_objectManager.mappingProvider setMapping:locationMapping forKeyPath:@"location"];

RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Groups class]];
[venueMapping mapRelationship:@"location" withMapping:locationMapping];
[_objectManager.mappingProvider setMapping:venueMapping forKeyPath:@"groups"];

RKObjectMapping *responseMapping = [RKObjectMapping mappingForClass:[Response class]];
[responseMapping mapRelationship:@"groups" withMapping:venueMapping];
[_objectManager.mappingProvider setMapping:responseMapping forKeyPath:@"response"];

return self;

以下是“locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation”中的代码

    NSString *resourceURLString = [NSString stringWithFormat:@"/v2/venues/search?ll=%f,%f&limit=10&client_id=LEA1MYN1Z1QWSBFIOA1T4FREVVNF0R1ADQKMA0AMGL3CN5N4&client_secret=M2W204MKEAO4KV5L4ZXUYWK2GC32PO0KT5PWYJQBP4FKBTMO",newLocation.coordinate.latitude, newLocation.coordinate.longitude];

[[RKObjectManager sharedManager] loadObjectsAtResourcePath:resourceURLString delegate:self];
[_locationManager stopUpdatingLocation];

最后这段代码在“objectLoader:(RKObjectLoader *)objectLoader didLoadObjects:(NSArray *)objects”

_objects = [objects retain];
NSLog(@"object that i receive is %@",objects);

以下是我在控制台中得到的响应:

2012-02-26 13:15:39.872 restKitPractice[8609:690b] W restkit.object_mapping:RKObjectMappingOperation.m:372 警告:映射嵌套对象失败:(空)2012-02-26 13:15:39.873 restKitPractice[8609:207] 我收到的对象是 ( “响应:0x6b5cb20”)

您可以使用此链接从 Foursquare 检查 Venues json:

https://api.foursquare.com/v2/venues/search?ll=40.562362,-111.938689&limit=10&client_id=LEA1MYN1Z1QWSBFIOA1T4FREVVNF0R1ADQKMA0AMGL3CN5N4&client_secret=M2W204MKEAO4KV5L4ZXUYWK2GC32PO0KT5PWYJQBP4FKBTMO

任何帮助或建议将不胜感激,因为我真的在为这个问题而苦苦挣扎。

谢谢维克

最佳答案

你应该看看 object mapping docs .

您的映射定义与您尝试解析的 json 不匹配。

关于ios - RestKit 警告 - 警告 : Failed mapping nested object: (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9457310/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com