2

在 Restkit v0.10 中,可以使用从https://stackoverflow.com/a/12057398/871459获取的以下代码来完成到 NSDictionary 的映射

RKObjectMapping* mapping = [RKDynamicObjectMapping dynamicMapping];
mapping.objectMappingForDataBlock = ^(id data) {
    NSDictionary* object = [data objectForKey: @"object"];
    NSArray* keys = [object allKeys];

    RKObjectMapping* dataMapping = [RKObjectMapping objectMapping];
    //Use the keys to define mapping
    return dataMapping;
};

在 v0.20 中,这不再可能。如何在 Restkit v0.20 上实现相同的功能?

4

1 回答 1

0

在 0.20 中,他们使用RKDynamicMapping而不是 RKDynamicObjectMapping。我还没有测试,但答案可能在这里:

RKDynamicMapping* dynamicMapping = [RKDynamicMapping new];    
[dynamicMapping setObjectMappingForRepresentationBlock:RKObjectMapping *^(id data) {
    NSDictionary* object = [data objectForKey: @"object"];
    NSArray* keys = [object allKeys];

    RKObjectMapping* dataMapping = [RKObjectMapping objectMapping];
    //Use the keys to define mapping
    return dataMapping;
}]; 

或者看看他们的 0.20 教程

于 2013-03-19T04:00:53.920 回答