2014-02-18 47 views
0

请帮忙做一个映射,从以下JSON无法执行使用RestKit RKObjectMapping映射到JSON

{ 
meta: {} 
notifications: [] 
response: { 
suggestedFilters: {} 
suggestedRadius: 922 
headerLocation: "Manhattan" 
headerFullLocation: "Manhattan" 
headerLocationGranularity: "city" 
totalResults: 
suggestedBounds: {} 
groups: [ 
{ 
type: "Recommended Places" 
name: "recommended" 
items: [ 
{ 
reasons: {} 
venue: { 
id: "430d0a00f964a5203e271fe3" 
name: "Brooklyn Bridge Park" 
contact: {} 
location: {} 
categories: [] 
verified: 
stats: {} 
likes: {} 
like: 
rating: 
hours: {} 
specials: {} 
photos: {} 
hereNow: {} 
} 
tips: [] 
referralId: "e-0-430d0a00f964a5203e271fe3-0" 
} 
{ 

到会议地点的对象与性质

@property (nonatomic, copy) NSString *ID; 
@property (nonatomic, copy) NSString *name; 

我需要映射响应>组>场地> ID TO“id” 以及回答>小组>场所>名称TO“名字”

我写这个

NSIndexSet *statusCodeSet = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); 

    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:[MappingProvider venueMapping] 
                          method:RKRequestMethodGET 
                         pathPattern:@"/v2/venues/explore" 
                          keyPath:@"response" 
                         statusCodes:statusCodeSet]; 

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/venues/explore?ll=40.7,-74&oauth_token=%@", 
             [[DataManager sharedManager] baseURL], [[DataManager sharedManager] anonymusUserAccessToken]]]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request 
                     responseDescriptors:@[responseDescriptor]]; 

    [operation setCompletionBlockWithSuc..... 

,但它不工作

谢谢

回答

1

您不能直接,因为映射已经没有办法对付的索引到2门不同的阵列(组和项目)映射到这一水平。您需要创建处理这些数组的映射,在这种情况下,通过创建并映射到容器对象(组),以便处理items数组(以及它包含的场所)。

+0

非常感谢。你能告诉我该怎么做。我对RestKit完全陌生,感谢您的帮助。 –

+0

如果您有场地地图,请添加项目映射。该映射与场地映射有关系并用于响应描述符中。响应描述符变为'keyPath:@“response.groups”'。尝试一下,如果它不起作用,就将问题添加到问题中。 – Wain