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

标签 ios ios5 warnings restkit

我刚开始学习 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/

相关文章:

iOS SDK-如何获取 viewController 的 segue 标识符?

ios - 向 TextEditor 添加水平填充,但防止它因此在内部移动滚动条

objective-c - iOS - 访问可修改的原始音乐库数据?

Android Studio 3.0 - 警告alarmManager可能会产生NullPointerException

ios - 在iOS上启动codenameone应用程序时发出警告(“应用程序会降低设备速度”)

iOS8 UITableView 和 Cell - Autolayout Height - Shift/Vertical offset bug on touch and perform segue

ios - 以最简单的方式使 View Controller 可滚动

objective-c - iOS 5 : Make NSString Category include NSCFConstantString?

objective-c - 如何为 MKPlacemark 创建 addressDictionary?

c++ - 在 catch block 中使用 g++ 或 clang++ 启用未引用局部变量警告