Ios 使用多个根键的RestKit内存中映射
例如,我们有这样一个响应:Ios 使用多个根键的RestKit内存中映射,ios,objective-c,cocoa-touch,restkit,restkit-0.20,Ios,Objective C,Cocoa Touch,Restkit,Restkit 0.20,例如,我们有这样一个响应: { "authors":[ { "id":"9", "name":"Some User", "email":"some@email.com" } ], "comments":[ { "id":"5", "from":"Some Other User #1", "content":"Some comment"
{
"authors":[
{
"id":"9",
"name":"Some User",
"email":"some@email.com"
}
],
"comments":[
{
"id":"5",
"from":"Some Other User #1",
"content":"Some comment"
},
{
"id":"12",
"from":"Some Other User #2",
"content":"Some other comment"
}
],
"posts":[
{
"id":"1",
"title":"My new post",
"links":{
"author":"9",
"comments":[
"5",
"12"
]
}
}
]
}
在普通响应中,author
和comments
可能嵌套在posts
键中,RestKit可以轻松地将Post类与关联的author和/或Comment类之间的关系连接起来,这样您就可以执行Post.author
并轻松地获取所需的数据。但是,如果您没有使用核心数据,因此无法使用,则上面显示的响应不允许以这种方式轻松映射
我的问题是:如果您正在使用RKObjectMapping
w/内存对象,RestKit中是否有方法连接Post
模型和关联的Author
以及多个Comment
对象之间的关系?理想情况下,我希望有post.author
返回author
实例,而post.comments
返回一组Comment
实例
我在RestKit回购协议上发现了类似的问题,但没有任何信息可以解决。我也做了很多研究,但是我不能用RestKit中的
RKObjectMapping
来实现这一点。非常感谢您提供的任何指导。您是否遇到元数据映射?我相信你可以利用@root键来创建你想要的连接(即@“@root.authors.id”
)
我似乎找不到关于这方面的直接文档,但如果您有/获得访问权限,您可以看到拉动和表格 “有没有办法……”什么?你能更详细地描述一下你的目标吗?你没有说过映射结果应该是什么,或者你现在有什么映射…@Wain,对此感到抱歉!我只想让
帖子
嵌套作者
和评论
对象,就好像它是一个普通的嵌套对象一样dictionary@JoshCaswell很抱歉,编辑帖子澄清了这个问题,请考虑重新开放,任何帮助都非常感谢!