0

我目前正在尝试让 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)
    );
}

非常感谢!

4

1 回答 1

0

好的,发现错误。老实说非常愚蠢:

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

有时,只见树木不见森林。

于 2013-07-18T22:26:51.017 回答