我有一个基于 RestKit 的应用程序,其中包含一个映射类。一切似乎都很好。但是,当我检索对象时,RestKit 会发出警告:
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
警告出现两次(可能是因为 JSON 响应中有两个对象)。我该如何解决?
这是我的映射:
RKManagedObjectMapping* presentationMapping = [RKManagedObjectMapping mappingForClass:[Presentation class]];
presentationMapping.primaryKeyAttribute = @"presentationId";
[presentationMapping mapKeyPath:@"id" toAttribute:@"presentationId"];
[presentationMapping mapKeyPath:@"title" toAttribute:@"title"];
[presentationMapping mapKeyPath:@"description" toAttribute:@"descriptionText"];
[presentationMapping mapKeyPath:@"download_url" toAttribute:@"downloadUrlString"];
[presentationMapping mapKeyPath:@"download_file_size" toAttribute:@"downloadFileSize"];
[objectManager.mappingProvider setMapping:presentationMapping forKeyPath:@"presentation"];
这是我检索对象的方法:
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/presentations" delegate:self];
这是我的 JSON 结构(通过 curl 检索):
[
{
"presentation": {
"created_at":"2011-08-13T17:09:40+02:00",
"description":"Lorem ipsum",
"id":1,
"title":"Xxx",
"updated_at":"2011-08-13T17:09:40+02:00",
"download_url":"http://xxx.example.com/system/downloads/1/original/presentation1.zip?1313248180",
"download_file_size":171703
}
},
{
"presentation": {
"created_at":"2011-08-13T17:10:30+02:00",
"description":"Dolor sit amet",
"id":2,
"title":"Zzz",
"updated_at":"2011-08-15T00:22:10+02:00",
"download_url":"http://xxx.example.com/system/downloads/2/original/zzz.zip?1313360530",
"download_file_size":3182117
}
}
]
服务器是我控制的 Rails 3.0 应用程序,可以根据需要修改响应格式。
我正在使用 RestKit 0.9.3。