检查此 JSON 文档:
{
"result": {
"playlists": [
{
"name": "p1",
"songs": [
{
"title": "t",
"artist": "a"
},
{
"title": "t",
"artist": "a"
}
]
},
{
"name": "p2",
"songs": [
{
"title": "t",
"artist": "a"
},
{
"title": "t",
"artist": "a"
}
]
}
]
}
}
我可以仅映射此文档中的“歌曲”而不创建“歌曲”以外的任何其他实体。在这种情况下,我不在乎播放列表。我为 Song 实体制作了 RKEntityMapping。现在让 RKResponseDescriptor 我应该提供什么 keyPath 来匹配所有“歌曲”实体?
我尝试了“result.playlists.songs”,但这不起作用。
RKEntityMapping *songMapping = [RKEntityMapping mappingForEntityForName:@"Song"
inManagedObjectStore:[RKManagedObjectStore defaultStore]];
[songMapping addAttributeMappingsFromArray:@[@"title", @"artist"]];
RKResponseDescriptor *songsResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:songMapping
pathPattern:@"/playlists"
keyPath:@"result.playlists.songs"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:songsResponseDescriptor];
RestKit 是否强大到足以做到这一点?
有没有办法指定“播放列表”是一个数组,并且必须检查其所有对象的“歌曲”属性?
我知道如果我将播放列表与“PlayList”实体进行匹配,“result.playlists”会起作用,但我想跳过那个并更深入。可能吗?