我有我的服务器的JSON响应。 的数据,从RestKit日志采取看起来像这样:RestKit - Objectmapping!这里出了什么问题?
sourceObject: (
{
place = {
"place_id" = "3cc1e372-f9d9-11e0-aba9-9415ab1a8034";
placeinfo = {
latitude = "12.5846738815";
longtitude = "55.6815948486";
"place_id" = "3cc1e372-f9d9-11e0-aba9-9415ab1a8034";
};
timestamp = "2011-10-19 00:33:44";
};
},
{
place = {
"place_id" = "b65e36e0-f9d9-11e0-aba9-9415ab1a8034";
placeinfo = {
latitude = "12.5720376968";
longtitude = "55.6785774231";
"place_id" = "b65e36e0-f9d9-11e0-aba9-9415ab1a8034";
};
timestamp = "2011-10-19 00:37:08";
};
},
{
Timestamps = {
"latest_update" = "2011-10-18 17:12:09";
uuid = "8c6fb842-f99b-11e0-aba9-9415ab1a8034";
};
})and targetObject: (null)
的数据被映射到3个对象:
广场,Placeinfo和LatestDBUpdate。
的问题是:
在上述JSON响应有2分地方的对象和2个嵌套PlaceInfo对象,具有一个连接到一对多的关系。
还有一个涉及Timestamps关键字的LatestDBUpdate对象。
Restkit将映射3个Place对象,其中一个将全为NULL。 其他2个Place对象映射正确,关系也正确。 它当然只应该映射2个Place对象!
LatestDBUpdate映射也映射时间戳正确。
我已经确定,如果我删除了JSON响应的Timestamps部分,那么映射是正确的,只有2个地方对象。
但我需要时间戳部分在那里! 我不知道如何解决这个问题!任何想法 - 我真的可以使用一些输入,因为我已经使用了几个小时在这!
下面是使用的映射设置:
//Place mapping
if (!self.placeManagedObject){
self.placeManagedObject = [RKManagedObjectMapping mappingForClass:[Place class]];
self.placeManagedObject.primaryKeyAttribute = @"UUID";
self.placeManagedObject.setDefaultValueForMissingAttributes = YES;
[self.placeManagedObject mapKeyPath:@"place_id" toAttribute:@"UUID"];
[self.placeManagedObject mapKeyPath:@"timestamp" toAttribute:@"timestamp"];
}
//PlaceInformation mapping
if (!self.placeInfoManagedObject){
self.placeInfoManagedObject = [RKManagedObjectMapping mappingForClass:[PlaceInfo class]];
self.placeInfoManagedObject.primaryKeyAttribute = @"UUID";self.placeInfoManagedObject.setDefaultValueForMissingAttributes = YES;
[placeInfoManagedObject mapKeyPath:@"place_id" toAttribute:@"UUID"];
[placeInfoManagedObject mapKeyPath:@"longtitude" toAttribute:@"longtitude"];
[placeInfoManagedObject mapKeyPath:@"latitude" toAttribute:@"latitude"];
}
//latestDBUpdate timestamp mapping
if (!self.latestDBUpdateManagedObject){
self.latestDBUpdateManagedObject = [RKManagedObjectMapping mappingForClass:[LatestDBUpdate class]];
self.latestDBUpdateManagedObject.primaryKeyAttribute = @"latest_update";
[self.latestDBUpdateManagedObject mapKeyPath:@"latest_update"toAttribute:@"latest_update"];
[self.latestDBUpdateManagedObject mapKeyPath:@"uuid" toAttribute:@"uuid"];
}
//Set mapping relations
[self.placeManagedObject mapRelationship:@"placeinfo" withMapping:self.placeInfoManagedObject];
// Register mapping with the provider -
[self.objectManager.mappingProvider setMapping:self.placeManagedObject forKeyPath:@"place"];
[self.objectManager.mappingProvider setMapping:self.placeInfoManagedObject forKeyPath:@"placeinfo"];
[self.objectManager.mappingProvider setMapping:self.latestDBUpdateManagedObject forKeyPath:@"Timestamps"];