Im using Restkit OM2 to take in a json and map to objects on iphone. Im currently confused on how to structure the mappings and could do with some help.
下面是json案
{
-magic_verbs: [
-{
lemma: "work"
position: 5
score: "0.75"
value: "working"
}
-{
lemma: "head"
position: 0
score: "0.75"
value: "heading"
}
],
magic_advs: [
-{
lemma: "not"
position: 2
score: "0.6"
value: "not"
}
-{
lemma: "just"
position: 2
score: "0.6"
value: "just"
}
]
}
i 只需要从其中每个领域提取玉米和价值。 例如,饮料类含有饮料。
@interface Verbs : NSManagedObject {
}
@property (nonatomic,retain) NSString *lemma;
@property (nonatomic,retain) NSString *value;
@end
@implementation Verbs
@synthesize lemma,value;
@end
之后一读于json,并绘制地图,其代码如下:
objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://localhost:3000"];
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"RKRelationshipMappingExample.sqlite"];
[RKObjectManager setSharedManager:objectManager];
RKObjectMappingProvider* provider = [[RKObjectMappingProvider new] autorelease];
RKObjectMapping* verbMapping = [RKObjectMapping mappingForClass:[Verbs class]];
[verbMapping mapKeyPath:@"lemma" toAttribute:@"lemma"];
[verbMapping mapKeyPath:@"value" toAttribute:@"value"];
[provider setMapping:verbMapping forKeyPath:@"magic_verbs"];
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:@"/api/users/1/magic_words" objectMapping:verbMapping delegate:self];
我也为奇迹测绘做了同样的工作。 我还有一个称为“词”的类别,包含2个线索,以包含物体测绘数据。 但是,不能肯定如何落实这一点并将它们正确地联系起来。
@interface Words : NSObject {
NSArray *_verbs;
NSArray *_adjs;
}
@property (nonatomic, retain) NSArray *verbs,*adjs;
@end
感谢在这方面提供任何帮助和指导。 我研究了卡塔洛项目的例子,并且能够取得这一进展,但一直能够主宰这一概念,将其应用于我自己的杰森档案。
thanks
G