2013-01-10 215 views
1

我正在嘗試使用restkit來讀取/解析xml提要。其中包含藝術家的嵌套數組。我可以映射其他關係,但我不清楚我與下面的藝術家關係有什麼關係。Restkit映射覆雜的嵌套數組

我的數據集的樣子:

<JamBase_Data> 
<Results_Title>Jersey City, NJ</Results_Title> 
<event> 
<event_id>1896611</event_id> 
<artists> 
    <artist> 
     <artist_id>96929</artist_id> 
     <artist_name>The Happy Problem</artist_name> 
    </artist> 
    <artist> 
     <artist_id>29817</artist_id> 
     <artist_name>Craig Greenberg</artist_name> 
    </artist> 
    </artists> 
<event_date>1/9/2013</event_date> 
<venue> 
<venue_id>48553</venue_id> 
<venue_name>The Cake Shop</venue_name> 
<venue_city>New York</venue_city> 
<venue_state>NY</venue_state> 
<venue_zip>10002</venue_zip> 
</venue> 
<event_url> 
http://www.jambase.com/Shows/Event.aspx?eventID=1896611 
</event_url> 
</event> 
</JamBase_Data> 

映射:

RKObjectMapping *eventMapping = [RKObjectMapping mappingForClass:[Event class]]; 
RKObjectMapping *artistMapping = [RKObjectMapping mappingForClass:[Artist class]]; 
RKObjectMapping *venueMapping = [RKObjectMapping mappingForClass:[Venue class]]; 

[artistMapping mapKeyPathsToAttributes: @"artist_name",@"artist_name", nil]; 
[venueMapping mapKeyPathsToAttributes: @"venue_city",@"venue_city",@"venue_state",@"venue_state", @"venue_name", @"venue_name", nil]; 

[objectManager.mappingProvider setMapping:eventMapping forKeyPath:@"JamBase_Data.event"]; 


[eventMapping mapKeyPath:@"artists" toRelationship:@"artists" withMapping:artistMapping]; 
[eventMapping mapKeyPath:@"venue" toRelationship:@"venue" withMapping:venueMapping]; 

Venue.h

@interface Event : NSObject 
@property (nonatomic, strong) NSSet *artists; 
@property (strong, nonatomic) Venue *venue; 

@end

Artist.h

@interface Artist : NSObject 
@property (nonatomic, strong) NSNumber *artist_id; 
@property (nonatomic, strong) NSNumber *artist_name; 

我可以正確地繪製地圖,但無法弄清楚如何讓藝術家進行地圖繪製。有什麼我需要做的,以告訴對象經理做出事件?

任何幫助將不勝感激,因爲這是我第一次進入iOS開發。

回答

0

您在XML中看到的Artists對象轉換爲NSArray。現在包含Artists類型的對象。你有這種想法嗎?

+0

我預計藝術家將映射到NSSet * Venue中的藝術家。但是當我嘗試閱讀它時,我沒有收到任何填充的元素。「 – FriendlyMikhail