我想使用RestKit (OM2)将给定的数组索引映射到一个属性。这是我的JSON:
{
"id": "foo",
"position": [52.63, 11.37]
}
我希望将其映射到这个对象:
@interface NOSearchResult : NSObject
@property(retain) NSString* place_id;
@property(retain) NSNumber* latitude;
@property(retain) NSNumber* longitude;
@end
我无法想出如何将JSON中位置数组的值映射到我的Objective-C类的属性中。目前的映射如下:
RKObjectMapping* resultMapping = [RKObjectMapping mappingForClass:[NOSearchResult class]];
[resultMapping mapKeyPath:@"id" toAttribute:@"place_id"];
现在我该如何添加纬度/经度的映射?我尝试了很多方法,但都没有成功。例如:
[resultMapping mapKeyPath:@"position[0]" toAttribute:@"latitude"];
[resultMapping mapKeyPath:@"position.1" toAttribute:@"longitude"];
是否有一种方法可以将JSON中的position[0]
映射到我的对象中的latitude
?