我想基於從Web服務中檢索的JSON在覈心數據中創建節點實體的層次結構。當我唯一的關係信息是JSON結構時,如何在RestKit中設置關係?
這裏是我的JSON結構
http://cl.ly/image/0r2x3E210m1U
的示例中,我無法弄清楚如何建立的映射關係。
有人可以幫我嗎?我正在使用最新的RestKit版本。
我想基於從Web服務中檢索的JSON在覈心數據中創建節點實體的層次結構。當我唯一的關係信息是JSON結構時,如何在RestKit中設置關係?
這裏是我的JSON結構
http://cl.ly/image/0r2x3E210m1U
的示例中,我無法弄清楚如何建立的映射關係。
有人可以幫我嗎?我正在使用最新的RestKit版本。
你不能。 在JSON/RESTKIT中,你不能提供一個遞歸結構的ob對象。 只需嘗試一次獲取對象級別,如果想要更深入地探索一個新的查詢。
如果有人訪問此屬性,那麼您的'節點'類應該具有'節點'屬性,並使用一種延遲加載。
如果失敗:
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]];
是的,但由於某種原因,它映射到它的自我,這意味着節點實例1將將節點實例1映射爲其父節點和子節點。 – Weston 2013-03-07 18:34:45
我有點想到這一個。我結束了自己的解析器。 – Weston 2013-03-15 15:17:40
這是不正確的。 – fumoboy007 2013-03-17 22:20:03