当我请求 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/