是否可以通过 mapKeyPath 点语法强制 RestKit 对象映射器映射到数组中的特定嵌套对象?
这是我试图映射的响应
<result is_array="true">
<item>
<_field_data>
<nid>
<entity>
<field_region>
<und is_array="true">
<item>
<value>1</value>
</item>
</und>
</field_region>
....
我只对为 field_region 返回的第一个项目感兴趣。
映射这个的正确方法是什么?
我尝试了各种迭代:
RKManagedObjectMapping *record = [RKManagedObjectMapping mappingForClass:[MyRecordClass class] inManagedObjectStore:objManager.objectStore];
[record mapKeyPath:@"_field_data.nid.entity.field_region.und.0.item.value" toAttribute:@"region"];
我不断收到类似于以下的错误:
T restkit.object_mapping:RKObjectMappingOperation.m:152 Found transformable value at keyPath '_field_data.nid.entity.field_region.und.0.item.value'. Transforming from type '__NSArrayI' to 'NSNumber'
W restkit.object_mapping:RKObjectMappingOperation.m:232 Failed transformation of value at keyPath '_field_data.nid.entity.field_region.und.0.item.value'. No strategy for transforming from '__NSArrayI' to 'NSNumber'
我通过以下方式调用映射:
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:kMyResourcePath usingBlock:^(RKObjectLoader* loader) {
loader.objectMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[MyRecordClass class]];
loader.method = RKRequestMethodGET;
loader.delegate = self;
loader.targetObject = nil;
}];
有任何想法吗?最欣赏!