我有以下Json结构,我想用Restkit
进行映射"spells": {
"wizard": {
"fireball": {
"text": "Burst of Flames",
"mana": 10,
},
"mpheal": {
"text": "Ethereal Surge",
"mana": 30,
},
},
"warrior": {
"smash": {
"text": "Brutal Smash",
"mana": 25,
},
"defensiveStance": {
"text": "Defensive Stance",
"mana": 25,
}
}
}
现在我想将这些映射到个人" Spell"实体。这些实体应该都有一个字段" class",来自json的值(p.e。" warrior"" wizard")。有没有人有想法,我怎么能做到这一点? (我宁愿不为这些类创建一个新的实体。)
这是我目前用于映射的内容:
RKEntityMapping *spellMapping = [RKEntityMapping mappingForEntityForName:@"Spell" inManagedObjectStore:managedObjectStore];
spellMapping.forceCollectionMapping = YES;
[spellMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"key"];
[spellMapping addAttributeMappingsFromDictionary:@{
@"(key).text": @"text"
@"(key).mana": @"mana"}];
我设法通过将它应用于每个Class对象来获取所有对象(所以" spells.wizard"和#34; spells.warrior")。但是这样,我无法填充包含该咒语类名的字段。是否有类似于针对Keypath的addAttributeMappingFromKeyOfRepresentationToAttribute?