这是我的反应机构:
{
"bsqn": 5,
"results": [
{
"sqn": 1,
"res": "oldu!"
}
]
}我想通过使用这个keyPath:"bsqn.res“来获得我真正需要的"res”属性。
//TestResponse.h
@interface TestResponse : NSObject
@property (nonatomic, copy) NSString *res;
+ (RKObjectMapping *)objectMapping;
@end
// TestResponse.m
@implementation TestResponse
+ (RKObjectMapping *)objectMapping
{
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[self class]];
[mapping addAttributeMappingsFromDictionary:@{@"res": @"res"}];
return mapping;
}
@end
RKResponseDescriptor *newDesc = [RKResponseDescriptor responseDescriptorWithMapping:
[TestResponse objectMapping] method:RKRequestMethodPOST pathPattern:nil keyPath:@"bsqn.res"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];但是它给出了这样的错误:
this class is not key value coding-compliant for the key hashcode有办法做我想做的事吗?谢谢..
发布于 2013-11-06 16:14:39
在您的JSON中,bsqn.res不存在。bsqn只是一个字符串。
将响应描述符更改为keyPath:@"results",RestKit将将结果数组中的每个项映射到TestResponse的新实例中,并设置res属性。
https://stackoverflow.com/questions/19817004
复制相似问题