我正在尝试将当前的RestKit升级到0.20.3,在一种情况下,我需要将结果作为字典返回,而不是映射到任何对象。
不幸的是,下面的代码导致了一个基本上为空的RKMappingResult对象,尽管RestKit中有一个正确的字典确实存在(我检查过)。
[self.objectManager addResponseDescriptor:[RKResponseDescriptor responseDescriptorWithMapping:[RKObjectMapping mappingForClass:[NSMutableDictionary class]]
method:RKRequestMethodGET
pathPattern:@"permission.json"
keyPath:nil
statusCodes:nil]];
[self loadObject:[[NSMutableDictionary alloc] init]
method:RKRequestMethodGET
path:@"permission.json"
params:nil
success:^(RKObjectRequestOperation *op, RKMappingResult *result) {
if (success)
success([result dictionary]);
}
failure:^(RKObjectRequestOperation *op, NSError *error) {
if (failure)
failure(error);
}];
加载对象调用以下内容:
RKObjectRequestOperation *const operation =
[self operationForObject:object
method:method
path:path
params:params
success:success
failure:failure];
[self.objectManager enqueueObjectRequestOperation:operation];
return operation;
任何人都可以告诉我如何说服RestKit给我一本字典吗?
答案 0 :(得分:3)
这确实是为字典结果创建映射实例的正确方法之一:
[RKObjectMapping mappingForClass:[NSMutableDictionary class]]
但是你仍然需要设置应该映射的键名,否则RestKit就不会映射。