我正在使用RestKit的对象映射将JSON数据映射到对象。 是否可以将我的Objective-C类中的纬度和经度JSON属性映射到CLLocation
变量?RestKit RKObjectMapping到CLLocation
的JSON:
{ "items": [
{
"id": 1,
"latitude": "48.197186",
"longitude": "16.267452"
},
{
"id": 2,
"latitude": "48.199615",
"longitude": "16.309645"
}
]
}
类应该映射到:
@interface ItemClass : NSObject
@property (nonatomic, strong) CLLocation *location;
@end
最后,我想打电话itemClassObj.location.longitude
让我的价值来自JSON响应的纬度。
我以为这样的事情会起作用,但事实并非如此。
RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[ItemClass class]];
[mapping mapKeyPath:@"latitude" toAttribute:@"location.latitude"];
[mapping mapKeyPath:@"longitude" toAttribute:@"location.longitude"];
非常感谢您的帮助。
是否有一种方法,火灾在我的模型中,只要一切都被映射了?然后,我可以简单地将映射的经纬度值分配给CLLocationCoordinate ... – alex
为什么不在您的模型上创建一个只读属性来为您做这个?只要你准备好将它放在地图上,就可以调用它......由于评论无法格式化代码,所以请参阅上面的编辑。 –
此外,我认为就对你的后映射问题的直接反应而言,'objectMapperDidFinishMapping:'? –