GOT:
@property(nonatomic, retain) NSString *user;
@property(nonatomic, retain) NSString *token;
@property(nonatomic, retain) NSArray *list;// NSNumber only please!
和
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[MyResponse class]];
[mapping addAttributeMappingsFromDictionary:@{
@"user" : @"user",
@"token" : @"token",
@"list" : @"list",
}];
我收到Json:
{"user":"foobar","token":"azerty","list":[0,1,"2"]}
不幸的是,list
将是NSString和NSNumber的混合体。如何告诉RestKit 0.2x我只想在我的NSArray中使用NSNumber或NSString?
答案 0 :(得分:2)
RestKit
肯定会使用KVC,如果您只想要数字,则可以使用相应的keyPath,例如如果我希望数字始终是整数,我可以使用integerValue
和NSNumber
都有的方法NSString
:
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[MyResponse class]];
[mapping addAttributeMappingsFromDictionary:@{
@"user" : @"user",
@"token" : @"token",
@"list.integerValue" : @"list",
}];
答案 1 :(得分:1)
为什么不只是重写一个JSON解析器来完成你的特定任务,为什么不只是后处理'list'并用if([list[i] isKindOfClass:[NSString class]])
检查每个对象并将其转换为NSNumber?