【发布时间】:2011-12-09 07:12:01
【问题描述】:
我在映射中遇到问题:latest_update 字段 JSON 数据。
从我的网络服务接收这个 JSON 数据:
{"Places":[
{"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974979a",
"timestamp": "2011-10-02 23:24:42"
},
{"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974933x",
"timestamp": "2011-10-02 23:24:42"
},
{"latest_update":"2011-10-13 12:16:17"}]
}
以及我用于托管映射的代码片段:
//Place mapping
if (!self.placeManagedObject){
self.placeManagedObject = [RKManagedObjectMapping
mappingForClass:[Place class]];
self.placeManagedObject.primaryKeyAttribute = @"UUID";
self.placeManagedObject.rootKeyPath = @"places";
[self.placeManagedObject mapKeyPath:@"place_ID"
toAttribute:@"UUID"];
[self.placeManagedObject mapKeyPath:@"timestamp"
toAttribute:@"timestamp"];
[self.placeManagedObject mapRelationship:@"PlaceInformation"
withMapping:self.placeInfoManagedObject];
// Register mapping with the provider - means it will look for
places in the JSON input
[objectManager.mappingProvider
setMapping:self.placeManagedObject forKeyPath:@"places"];
}
//latestDBUpdate timestamp mapping
if (!self.latestDBUpdateManagedObject){
self.latestDBUpdateManagedObject = [RKManagedObjectMapping
mappingForClass:[LatestDBUpdate class]];
self.latestDBUpdateManagedObject.primaryKeyAttribute =
@"latest_update";
self.latestDBUpdateManagedObject.rootKeyPath = @"places";
[self.latestDBUpdateManagedObject mapKeyPath:@"latest_update"
toAttribute:@"latest_update"];
// Register mapping with the provider - means it will look for
places in the JSON input
[objectManager.mappingProvider
setMapping:self.latestDBUpdateManagedObject
forKeyPath:@"latest_update"];
}
RestKit 将正确映射 Place 对象,即: {"place_ID": "7cceedda-ed3a-11e0-a1a8-858e3974979a", “时间戳”:“2011-10-02 23:24:42” } ... 放置物体, 但 latest_update 未映射到 LatestDBUpdate 类 对象,我无法让它工作。
我希望有人知道它是如何完成的,因为几个小时 搜索和尝试并没有让我更接近解决方案。 谢谢托马斯
【问题讨论】:
标签: objective-c ios restkit object-object-mapping