Reputation: 687
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
Upvotes: 0
Views: 84
Reputation: 119031
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).
Upvotes: 1