ios - 在 RESTkit 中为 JSON 数组中的对象指定特定映射?

标签 ios json restkit

当我请求 UserProfile 对象列表时,我从 django-rest-framework 收到此 JSON:

[
    {
        "gender": 1, 
        "show_gender": true, 
        "show_real_name": true
    }, 
    {
        "gender": 2, 
        "show_gender": true, 
        "show_real_name": true
    }
]

但是我不知道如何使用 Restkit 配置我的映射。 Restkit 似乎期望 dictionary instead of a list ,因为它似乎使用字典的键作为“KeyPath”来识别必要的映射。有没有办法手动指定接收对象的映射?

最佳答案

明白了!

// define a mapping
RKObjectMapping* userMapping = [RKObjectMapping mappingForClass:[ERUser class]];
[userMapping mapAttributes:
 @"gender",
 @"show_gender",
 @"show_real_name",
 nil];

// add the mapping anonymously
[objectManager.mappingProvider addObjectMapping:userMapping];

// tell the mapping provider which mapping to use
RKObjectMapping* articleMapping = [[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[ERUser class]];
[objectManager loadObjectsAtResourcePath:@"/users" objectMapping:articleMapping delegate:self];

关于ios - 在 RESTkit 中为 JSON 数组中的对象指定特定映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9276705/

相关文章:

ios - 如何以编程方式为 UIBarbutton 项目设置动画

json - 在bash中使用awk合并两个Json文件

c# - 忽略序列化为 JSON 时抛出异常的类成员

java - 接口(interface)和@RequestBody

objective-c - RestKit - POST 响应对象映射

ios - 关于CS193P作业1的问题

ios - UIScrollView 切断底部内容

iphone - 使用 Restkit 和 Core data 检索图像

iphone - RestKit 映射嵌套字典中的值

ios - AFNetworking 2.0 和背景图片