gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:23:26 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com