0

please help make a mapping from following 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"
}
{

to Venue object with properties

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

I need to map response > groups > venue > id TO "id" and response > groups > venue > name TO "name"

I write this

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.....

but it is not working

Thank you

Ali Amin
  • 667
  • 5
  • 17

1 Answers1

1

You can't map directly to that level because the mapping has no way to deal with indexing into 2 different arrays (groups and items). You need to create mappings which deal with these arrays, in this case by creating and mapping into a container object (group) so that you can process the items array (and the venue it contains).

Wain
  • 118,658
  • 15
  • 128
  • 151
  • Thank you very much. Can you please show how to do that. I'm totally new to RestKit.I appreciate your help. – Ali Amin Feb 19 '14 at 07:34
  • As you have a venue mapping, add an item mapping. That mapping has a relationship to the venue mapping and is used in the response descriptor. The response descriptor changes to ` keyPath:@"response.groups"`. Give it a try and add your mappings to the question if it doesn't work. – Wain Feb 19 '14 at 08:23