【发布时间】:2014-02-18 23:15:46
【问题描述】:
谁能帮我在restkit 0.20中映射这个json对象?
"feeds" : [
{
"id": 32131354,
"caption": "Blah Blah Blah.",
"story" : "blah blah someone blah blah someone else",
"story_tags": {
"0": [
{
"id": 21231654,
"name": "Someone",
"offset": 0,
"length": 25,
"type": "page"
}
],
"33": [
{
"id": 3213212313,
"name": "Someone else",
"offset": 33,
"length": 12,
"type": "page"
}
]
},
}
{
...
}
]
我非常感谢任何帮助。这就是现在正在做的事情:
RKEntityMapping *feedsMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([FacebookFeed class]) inManagedObjectStore:managedObjectStore];
feedsMapping.identificationAttributes = @[@"id"];
[feedsMapping addAttributeMappingsFromDictionary:@{
@"caption" : @"caption",
@"id" : @"id",
@"story" : @"story",
}];
这是用于关系映射
RKEntityMapping *facebookFeedStoryTagsMapping = [RKEntityMapping mappingForEntityForName:NSStringFromClass([FacebookFeedStoryTag class]) inManagedObjectStore:managedObjectStore];
facebookFeedStoryTagsMapping.identificationAttributes = @[@"id"];
[facebookFeedStoryTagsMapping addAttributeMappingToKeyOfRepresentationFromAttribute:@"offset"];
[facebookFeedStoryTagsMapping addAttributeMappingsFromDictionary:@{
@"(offset).id" : @"id",
@"(offset).length" : @"length",
@"(offset).name" : @"name",
@"(offset).type" : @"type",
}];
[feedsMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"story_tags" toKeyPath:@"story_tags" withMapping:facebookFeedStoryTagsMapping]];
但我收到以下错误:
restkit.object_mapping:RKMappingOperation.m:745 Key path 'story_tags' yielded collection containing another collection rather than a collection of objects: (
(
{
id = 31314654654;
length = 25;
name = "Someone";
offset = 0;
type = page;
}
)
)
【问题讨论】:
标签: objective-c restkit restkit-0.20