我正在尝试映射以下对象:
{"walletAccepted":false,"creditCardTypesAccepted":["visa","mastercard","discover","americanexpress"],"paypalAccepted":false}
具有相同属性的对象。但是,ResourcePath是动态的,因为它与/ paymentmethods / zone /:internalZoneCode
一致。我在映射时所做的每一次尝试总是以“映射期间遇到的错误:无法找到keyPath的对象映射:''”
我认为问题在于没有根密钥/密钥路径。我也试过以下但没有运气:
RKURL *rkUrl = [RKURL URLWithBaseURL:[RKClient sharedClient].baseURL resourcePath:[NSString stringWithFormat:@"/paymentoptions/zone/%@", zoneNumber]];
RKObjectLoader* loader = [[RKObjectLoader alloc] initWithURL:rkUrl mappingProvider:[RKObjectManager sharedManager].mappingProvider];
loader.method = RKRequestMethodGET;
loader.delegate = self;
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[PMZonePaymentMethods class]];
[loader send];
答案 0 :(得分:0)
我发现实现它的方法是配置映射,并将映射添加到没有密钥路径或资源的对象管理器
所以这样:
RKObjectMapping* zonePaymentMethodsMapping = [RKObjectMapping mappingForClass:[PMZonePaymentMethods class]];
[zonePaymentMethodsMapping mapKeyPath:@"walletAccepted" toAttribute:@"walletAvailable"];
[zonePaymentMethodsMapping mapKeyPath:@"creditCardTypesAccepted" toAttribute:@"cards"];
[zonePaymentMethodsMapping mapKeyPath:@"paypalAccepted" toAttribute:@"paypalAvailable"];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:zonePaymentMethodsMapping];
并使用它来发出请求:
RKURL *rkUrl = [RKURL URLWithBaseURL:[RKClient sharedClient].baseURL resourcePath:[NSString stringWithFormat:@"/paymentoptions/zone/%@", zoneNumber]];
RKObjectLoader* loader = [[RKObjectLoader alloc] initWithURL:rkUrl mappingProvider: [RKObjectManager sharedManager].mappingProvider];
loader.method = RKRequestMethodGET;
loader.delegate = self;
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[PMZonePaymentMethods class]];
[loader send];