gpt4 book ai didi

ios - RestKit:一对多关系映射

转载 作者:行者123 更新时间:2023-11-28 22:29:23 24 4
gpt4 key购买 nike

我正在尝试使用 RestKit 解析 github 的 gist api 响应。这是 json 的片段:

  {
"url": "https://api.github.com/gists/6004248",
...
"html_url": "https://gist.github.com/6004248",
"files": {
"ApplicationContext.h": {
"filename": "ApplicationContext.h",
"type": "text/plain",
"language": "Objective-C",
"raw_url": "https://gist.github.com/raw/6004248/4531c7534585b273c55ca71ce9020418b7ed271b/ApplicationContext.h",
"size": 481
},
"ApplicationContext.m": {
"filename": "ApplicationContext.m",
"type": "text/plain",
"language": "Objective-C",
"raw_url": "https://gist.github.com/raw/6004248/27a3881f9c5adde700b75199076a5ce259d0b568/ApplicationContext.m",
"size": 542
}
},
...
"user": {
...
},
"comments_url": "https://api.github.com/gists/6004248/comments"
},

一切正常,但我的文件关系有问题。这是负责文件的代码片段:

RKObjectMapping *gistMapping = [RKObjectMapping mappingForClass:[MBGist class]];
[gistMapping addAttributeMappingsFromDictionary: @{@"url": @"url", @"html_url": @"htmlUrl", @"description": @"description"}];

RKObjectMapping *fileMapping = [RKObjectMapping mappingForClass:[MBFile class]];
[fileMapping addAttributeMappingsFromDictionary:@{@"filename": @"filename", @"language": @"language", @"type":@"type"}];

[gistMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"files" toKeyPath:@"files" withMapping:fileMapping]];

但我的 MBGist 类对象中有空文件数组。

有人可以帮我吗?

最好的问候,迈克尔

最佳答案

请引用Restkit ObjectMapping中的处理动态嵌套属性部分

关于ios - RestKit:一对多关系映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17909412/

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