Restkit简单的NSDictionary映射

Riz*_*zon 2 objective-c ios restkit restkit-0.20

看起来像一个非常简单的任务,但我发现自己在努力..我有这个JSON响应:

{"data":
    {"badParams":
        {"arbitraryKey":"arbitraryValue",
        "arbitraryKey2":"arbitraryValue2",
        "arbitraryKey3":"arbitraryValue3" ,
        ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想解析对NSDictionary的响应,包含key:value我在响应中得到的所有对:

NSDictionary *response == {"arbitraryKey":"arbitraryValue",
            "arbitraryKey2":"arbitraryValue2",
            "arbitraryKey3":"arbitraryValue3",...} 
Run Code Online (Sandbox Code Playgroud)

我试过RKDynamicMapping却无法做到:

有什么建议吗?

Obe*_*and 5

RestKit不适用于NSDictionarys.但如果有必要,你可以做一些丑陋的解决方法......

此类将字典包装在容器类中,该容器类将KVC调用转发到setObject:forKey字典.

@interface RestKitDictionaryContainer : NSObject
@property (nonatomic, strong) NSMutableDictionary * dictionary;
@end

@implementation RestKitDictionaryContainer

- (id)init
{
    self = [super init];
    if (self) {
        _dictionary = [NSMutableDictionary dictionary];
    }
    return self;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    [_dictionary setObject:value forKey:key];
}

-(id)valueForUndefinedKey:(NSString *)key {
    return [_dictionary objectForKey:key];
}
@end
Run Code Online (Sandbox Code Playgroud)

现在你必须像往常一样做所有的映射.在RestKit调用之后,您只需要从该类中获取字典或将其用作字典.嗯,我觉得这很难看,不应该用,但这是你的决定......