2012-07-26 78 views
0

我試圖映射以下對象:將沒有root密鑰的對象映射到動態url?

{"walletAccepted":false,"creditCardTypesAccepted":["visa","mastercard","discover","americanexpress"],"paypalAccepted":false} 

要具有相同屬性的對象。但是,ResourcePath是動態的,因爲它沿着/ paymentmethods/zone /行:internalZoneCode

我在映射時所做的每一次嘗試總是以「映射期間遇到的錯誤:無法找到對象映射對於keyPath:''「

我認爲問題是沒有root密鑰/密鑰路徑。我也嘗試沒有運氣以下:

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

我發現做到這一點的方法是配置的映射,並添加映射對象管理沒有一個關鍵路徑或resourcek

所以像這樣:

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]; 
相關問題