【问题标题】:RestKit warning: "Found a collection containing only NSNull values..."RestKit 警告:“找到一个只包含 NSNull 值的集合......”
【发布时间】:2011-08-15 11:07:32
【问题描述】:

我有一个基于 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。

【问题讨论】:

    标签: objective-c restkit


    【解决方案1】:

    此警告并不表示映射不正确。事实上,这条消息可能应该被记录为 Debug 或 Trace,因为它可以作为正常对象映射的一部分出现。我将提交一个拉取请求以更改未来的日志级别。所以请放心,您的映射很好,无需更改即可消除此警告。 :)

    【讨论】:

      【解决方案2】:

      在最近安装的 RestKit 上仍然收到此警告,对 RestKit 代码进行了以下更改。

      FILE: RKPbjectMapper.m 
      FUNCTION: (BOOL)isNullCollection:(id)object
      LINE: 104
      

      改变了:

      RKLogWarning(@"Found a collection containing only NSNull values, considering the collection unmappable...");
      

      到:

      RKLogDebug(@"Found a collection containing only NSNull values, considering the collection unmappable...");
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-28
        • 1970-01-01
        • 2014-12-18
        • 2016-12-26
        • 2016-10-19
        • 2015-06-20
        • 1970-01-01
        • 2021-05-12
        相关资源
        最近更新 更多