RestKit 警告:“发现一个仅包含 NSNull 值的集合...”
我有一个基于 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。
I have a RestKit-based app with one mapped class. Everything seems to work fine. However, when I retrieve objects, RestKit emits a warning:
W restkit.object_mapping:RKObjectMapper.m:90 Found a collection containing only NSNull values, considering the collection unmappable...
The warning appears twice (presumably because there are two objects in JSON response). How can I fix that?
Here's my mapping:
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"];
Here's how I retrieve objects:
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/presentations" delegate:self];
Here's my JSON structure (retrieved via 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
}
}
]
The server is Rails 3.0 app which I control and can modify response format if needed.
I'm using RestKit 0.9.3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此警告并不表示映射不正确。事实上,此消息可能应该记录为“调试”或“跟踪”,因为它可能作为正常对象映射的一部分出现。我将提交拉取请求以更改将来的日志级别。因此,请放心,您的映射没有问题,无需进行任何更改即可消除此警告。 :)
This warning is not a sign of an improper mapping. In fact this message should probably be logged as Debug or Trace as it can occur as part of normal object mapping. I'll submit a pull request to change the log level for the future. So rest assured your mapping is fine and no changes are necessary to quiet this warning. :)
在最近安装的 RestKit 上仍然收到此警告,在 RestKit 代码中进行了以下更改。
更改为:
至:
Still getting this warning on the recently installed RestKit, made the following change in the RestKit code.
changed:
to: