在restkit中映射数组

在Restkit中使用objective-c。

我试图映射一个像这样的对象:

{

"key1":"key1",
"key2":"key2",
"key3":[{
         "otherkey1":"otherkey1",
         "otherkey2":"otherkey2"
        },
        {
         "otherkey1":"otherkey1",
         "otherkey2":"otherkey2"
        },
       ]

}

我正在做这样的事情:

RKObjectManager *objMan = [[RKObjectManager alloc] initWithHTTPClient: client];

RKObjectMapping *requestMapping = [RKObjectMapping requestMapping];
[requestMapping addAttributeMappingsFromArray:@[@"key1",
                                                @"key2",
                                                @"key3"]];
RKRequestDescriptor *requestDescriptor = [RKRequestDescriptor requestDescriptorWithMapping:requestMapping objectClass:[objContainer class] rootKeyPath:nil method:RKRequestMethodAny];

/**/
RKObjectMapping *requestMapping1 = [RKObjectMapping requestMapping];
[requestMapping1 addAttributeMappingsFromArray:@[@"otherkey1",
                                                @"otherkey2",
                                                ]];

RKRequestDescriptor *requestDescriptor1 = [RKRequestDescriptor     requestDescriptorWithMapping:requestMapping1 objectClass:[ContainerClient class] rootKeyPath:@"key3" method:RKRequestMethodAny];

RKObjectManager *manager = [RKObjectManager sharedManager];
[manager addRequestDescriptor:requestDescriptor];

RKObjectMapping *objMapping = [RKObjectMapping mappingForClass:[objContainer class]];
[objMapping addAttributeMappingsFromDictionary:@{
                                                 @"key1" : @"key1",
                                                 @"key2" : @"key2",
                                                 @"key3" : @"key3",
                                                 }];

/**/
RKObjectManager *manager1 = [RKObjectManager sharedManager];
[manager1 addRequestDescriptor:requestDescriptor1];


RKObjectMapping *objMapping1 = [RKObjectMapping mappingForClass:[ContainerClient class]];
[objMapping1 addAttributeMappingsFromDictionary:@{
                                                 @"otherkey1" : @"otherkey1",
                                                 @"otherkey2" : @"otherkey2",
                                                 }];
/**/

Classe ContainerClient

@属性(强,非原子)NSNumber * otherkey1;

@属性(强,非原子)NSString * otherkey2;

Class objContainer

@属性(强,非原子)NSNumber * key1;

@属性(强,非原子)NSNumber * key2;

@属性(强,非原子)NSMutableArray * key3;

有这样的代码与服务器进行通信时发送的对象没有列表和作品。 我如何映射列表?


你需要设置响应描述符 - 目前这些完全没有了。

如果key3应该包含ContainerClient实例,那么您也需要关系映射。 使用addRelationshipMappingWithSourceKeyPath:mapping:执行此操作addRelationshipMappingWithSourceKeyPath:mapping:

链接地址: http://www.djcxy.com/p/49199.html

上一篇: Mapping arrays in restkit

下一篇: RestKit Mapping a string array without key paths