RestKitObjectMapping关闭null对象的数组

时间:2013-09-27 20:33:31

标签: ios restkit restkit-0.20

RestKitObjectMapping数组关闭空对象

我想在Capital图像对象属性中映射CapitalImage对象。

//------------------------ The mapping I try to 


  [RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
                                   forMIMEType:@"text/html"];


    RKObjectMapping *CapitalImageMap = [RKObjectMapping mappingForClass:[CapitalImage class]];
    [CapitalImageMap addAttributeMappingsFromDictionary:@{
                                                     @"src":  @"src"
                                                     }];


    RKObjectMapping *CapitalMap = [RKObjectMapping mappingForClass:[Capital class]];
    [CapitalMap addAttributeMappingsFromDictionary:@{
                                                  @"name":  @"name",
                                                  @"text":  @"text"
                                                  }];

   [CapitalMap addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"images" toKeyPath:@"images" withMapping:CapitalImageMap]];

    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:CapitalMap
                                                                                            method:RKRequestMethodAny
                                                                                       pathPattern:nil
                                                                                           keyPath:nil
                                                                                       statusCodes:statusCodes];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.a10073.de4.dp10.ru/icapitals/capital.php"]];
    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {

        Capital *article = [result firstObject];
        NSLog(@"Mapped the article: %@ , %@", article.name,article.images.description);

    } failure:^(RKObjectRequestOperation *operation, NSError *error) { NSLog(@"Failed with error: %@", [error localizedDescription]); }];

    [operation start];

我得到了这个结果

2013-09-27 23:20:49.028 iCapitals v2[5099:c07] Mapped the article: London , (
    (null),
    (null),
    (null),

)

LOGS - http://www.a10073.de4.dp10.ru/icapitals/consoleresult.txt

请检查代码,告诉我做错了什么,谢谢!

1 个答案:

答案 0 :(得分:0)

您的映射看起来是正确的。日志显示映射正确进行。该问题似乎与CapitalImage类有关。为什么给出一个零描述?这可能是唯一的问题。所以你的数组日志是一个nil列表,但对象确实存在。

尝试记录每个对象的src。你看到其他问题吗?您是否实施了description方法?