Restkit映射复杂的嵌套数组

时间:2013-01-10 01:31:00

标签: ios objective-c xml restkit nsset

我正在尝试使用restkit来读取/解析xml提要。其中包含一组嵌套的艺术家。我可以映射其他关系,但我不清楚我对下面的艺术家关系做了什么。

我的数据集如下:

<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开发。

1 个答案:

答案 0 :(得分:0)

您在XML中看到的Artists对象转换为NSArray。现在包含艺术家类型的对象。你有没有想过这个?