我使用Restkit 0.26.0来映射多层的JSON,这个关键路径会导致麻烦:
productColorImages: [
{
id: 10,
productId: "232",
color: "green",
url: "exampleURL.com"
},
{
id: 11,
productId: "232",
color: "red",
url: "exampleURL.com"
},
{
id: 12,
productId: "232",
color: "blue",
url: "exampleURL.com"
}
],
我的映射
RKObjectMapping *transferProductColorImageMapping = [RKObjectMapping mappingForClass:[TransferProductColorImage class]];
[transferProductColorImageMapping addAttributeMappingsFromDictionary:@{ @"identifier" : @"id",
@"URL" : @"URL",
@"productId" : @"productId",
@"color" : @"color"
[getProductPageMapping
addRelationshipMappingWithSourceKeyPath:@"productColorImages" mapping:transferProductColorImageMapping];
目的地类
@interface TransferProductColorImage : NSObject
@property (nonatomic) NSNumber * identifier; // Mapps to id ;int 64
@property (nonatomic) NSString * URL;
@property (nonatomic) NSString * productId;
@property (nonatomic) NSString * color;
问题是生成的Object属于正确的类,但未填充属性。
我在日志中搜索并发现了这个:
2016-05-30 17:42:24.007 thebrandsapp[20697:7047455] T restkit.object_mapping:RKMappingOperation.m:1173 Performing mapping operation: <RKMappingOperation 0x7f9e3b9c11e0> for 'TransferProductColorImage' object. Mapping values from object {
color = green;
id = 10;
productId = 232;
url = "exampleURL.com";
} to object <TransferProductColorImage: 0x7f9e3b846d60> with object mapping (null)
在Model对象上,productColorImages是NSArray:
@property (nonatomic) NSArray <TransferProductColorImage *> * productColorImages;
这很奇怪,因为。如果映射为null,Restkit如何知道要使用的映射。是否有任何理由可以将对象映射设置为null?
更新:我发现标识符和颜色属性已正确映射,标识符和网址未正确映射。
答案 0 :(得分:1)
我将网址属性更改为小写:&#34;网址&#34;并且像我之前那样完全映射它并且它起作用。似乎全帽资产的名称投掷了RestKit。
我突然识别了标识符和id,现在它们也正确映射。