RestKit 0.2结果是一个nil对象的数组,虽然映射似乎是成功的

时间:2013-07-18 16:39:22

标签: ios restkit

我目前正在尝试使用我当前的项目运行RestKit 0.20,我遇到了一些困难。

我尝试将我的请求映射到一个对象,它显然是映射,但结果只返回空对象。

愿你们知道该怎么做。

这是代码

// Create object mapping for MVMyCar
  RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[MVMyCar class]];
  [mapping addAttributeMappingsFromDictionary:@{
                                                @"my_car_id"        :   @"uuid"
                                                }];

  // ResponseDescriptor
  RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:mapping
                                                                                          method:RKRequestMethodGET
                                                                                     pathPattern:kAPIPathGarage
                                                                                         keyPath:@"result"
                                                                                     statusCodes:[NSIndexSet indexSetWithIndex:200]];
  [[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];

  [RKObjectManager.sharedManager getObjectsAtPath:kAPIPathGarage parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
    NSLog(@"Mapping: %@",[mappingResult array]);
  } failure:^(RKObjectRequestOperation *operation, NSError *error) {

  }];

这是restkit跟踪:

2013-07-18 18:32:01.566 [12722:3a07] T restkit.object_mapping:RKMappingOperation.m:953 Performing mapping operation: <RKMappingOperation 0xc2920b0> for 'MVMyCar' object. Mapping values from object {
    "my_car_id" = 76;
} to object *nil description* with object mapping (null)
2013-07-18 18:32:01.569 [12722:3a07] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'my_car_id' to 'uuid'
2013-07-18 18:32:01.572 [12722:3a07] T restkit.object_mapping:RKMappingOperation.m:431 Found transformable value at keyPath 'my_car_id'. Transforming from type '__NSCFString' to 'NSNumber'
2013-07-18 18:32:01.573 [12722:3a07] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'my_car_id' to 'uuid'. Value: 76
2013-07-18 18:32:01.574 [12722:3a07] D restkit.object_mapping:RKMappingOperation.m:1021 Finished mapping operation successfully...

这是结果,实际上是数字:13个元素。

2013-07-18 18:32:01.575 [12722:3a07] D restkit.object_mapping:RKMapperOperation.m:403 Finished performing object mapping. Results: {
    result =     (
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null),
        (null)
    );
}

非常感谢!

1 个答案:

答案 0 :(得分:0)

好的发现错误。说实话是相当愚蠢的:

我的映射对象中有一个名为“description”的属性。

有时人们看不到树木的木材。