0

Web サービスから取得した JSON に基づいて、Core Data に Node エンティティの階層を作成しようとしています。

これが私のJSON構造のサンプルです

http://cl.ly/image/0r2x3E210m1U

マッピングの関係を設定する方法がわかりません。

誰かが私を助けてくれますか?最新の RestKit バージョンを使用しています。

4

2 に答える 2

0

できません。JSON / RESTKITでは、オブジェクトの再帰構造を提供することはできません。さらに深く掘り下げたい場合は、オブジェクトレベルを一度にフェッチして、新しいクエリを作成してみてください。

'node'クラスには、誰かがこのプロパティにアクセスする場合に、一種の遅延読み込みを伴う'nodes'プロパティが必要です。

于 2013-03-15T15:03:00.230 に答える
0

これが失敗した場合:

RKEntityMapping *nodeMapping = [RKEntityMapping mappingForEntityForName:@"Node" inManagedObjectStore:managedObjectStore];
[locationIconMapping addAttributeMappingsFromDictionary:@{
    @"name": @"name",
    @"type": @"type",
}];
[nodeMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nodes" toKeyPath:@"nodes" withMapping:nodeMapping]];

それではどうですか:

RKEntityMapping *nodeMapping1 = [RKEntityMapping mappingForEntityForName:@"Node" inManagedObjectStore:managedObjectStore];
[nodeMapping1 addAttributeMappingsFromDictionary:@{
    @"name": @"name",
    @"type": @"type",
}];

RKEntityMapping *nodeMapping2 = [RKEntityMapping mappingForEntityForName:@"Node" inManagedObjectStore:managedObjectStore];
[nodeMapping2 addAttributeMappingsFromDictionary:@{
    @"name": @"name",
    @"type": @"type",
}];

[nodeMapping1 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nodes" toKeyPath:@"nodes" withMapping:nodeMapping2]];
[nodeMapping2 addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nodes" toKeyPath:@"nodes" withMapping:nodeMapping1]];
于 2013-03-07T18:31:22.830 に答える