2014-02-18 85 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