2
我使用Restkit OM2來接收一個json並映射到iphone上的對象。我目前困惑於如何構建映射,並可以做一些幫助。Restkit OM2關係映射
下面是一個例子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"
}
]
}
我只需要外稃和值字段從每個這些。因此,例如動詞類包含
@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個包含對象映射數據的nsarrays。但我不確定如何實現這一點,並正確地連接起來。
@interface Words : NSObject {
NSArray *_verbs;
NSArray *_adjs;
}
@property (nonatomic, retain) NSArray *verbs,*adjs;
@end
任何幫助和指導,這是讚賞。我已經看過目錄項目中的示例,並且已經能夠運行,但還沒有能夠掌握概念,將其應用到我自己的json文件中。
感謝
摹
是的我發現它已經忘了更新這個問題。現在它工作得很好,這只是一些初期問題。謝謝 – glogic