我必须将数组映射到对象。我正在使用RKObjectMapping。一切都很好,但奖励数组没有被映射。获得奖励NSSet为null。
在@interface VBDealDetail : NSObject
@property(nonatomic,retain) NSString *dealName;
@property(nonatomic,retain) NSNumber *dealID;
@property(nonatomic,retain) NSSet *rewards;
在我的控制器类......
RKObjectManager *manager = [[VBRestKit sharedDataManager] objectManager];
RKObjectMapping *dealDetailEntryMapping = [RKObjectMapping mappingForClass:[VBDealDetailEntries class]];
RKObjectMapping *successResponseMapping = [RKObjectMapping mappingForClass:[VBCommonResponse class]];
[successResponseMapping addAttributeMappingsFromDictionary:@{
@"code": @"code",
@"msg" : @"message"
}];
RKObjectMapping* rewardMapping = [RKObjectMapping mappingForClass:[VBRewards class] ];
// NOTE: When your source and destination key paths are symmetrical, you can use addAttributesFromArray: as a shortcut instead of addAttributesFromDictionary:
[rewardMapping addAttributeMappingsFromDictionary:@{@"rewardId":@"rewardID",
@"rewardTitle":@"rewardTitle" }];
RKObjectMapping *dealDetailMapping = [RKObjectMapping mappingForClass:[VBDealDetail class]];
[dealDetailMapping addAttributeMappingsFromDictionary:@{
@"dealId" : @"dealID",
@"dealName" : @"dealName"
}];
[dealDetailEntryMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath: @"response"
toKeyPath: @"commonResponse"
withMapping: successResponseMapping]];
[dealDetailEntryMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath: @"dealDetails"
toKeyPath: @"dealDetail"
withMapping: dealDetailMapping]];
[dealDetailEntryMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"reward"
toKeyPath:@"rewards"
withMapping:rewardMapping]];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping: dealDetailEntryMapping
pathPattern: nil
keyPath: @"dealCollection"
statusCodes: RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[manager addResponseDescriptor:responseDescriptor];