0

I had a JSON response of this type:

{
"d": { "id": "1", "user": "test"}
}

which I was parsing with Restkit with the following code:

@interface ODataUser : NSObject<ODataObject>

@property (nonatomic, copy) NSString * id;
@property (nonatomic, copy) NSString * user;

-(NSString*)getId;
-(NSString*)getUser;
@end

RKObjectMapping *map = [RKObjectMapping mappingForClass:[ODataUser class]]; [mapping addAttributeMappingsFromDictionary: @{ @"id" : @"id", @"user" : @"user" } ];

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:map method:RKRequestMethodGET  pathPattern:nil keyPath:@"d" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

However, now my response has changed to something like this:

{
"d": { "results": [ {"id": "1", "user": "test"} ] }
}

How can I reflect those changes on the response on my code?

Rui
  • 5,900
  • 10
  • 38
  • 56
  • [Take a look at this](http://stackoverflow.com/questions/18890105/confusion-setting-mapping-in-rkobjectmapping-rest), may be helpful – Janak Nirmal Feb 26 '14 at 18:16

1 Answers1

0

Change your response descriptor to use:

keyPath:@"d.results"

as this will navigate into the d dictionary to get the results array and process all of the dictionaries it contains.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • In what way doesn't it work? Give details - errors, crash log? If neither, turn on trace logging and show the contents. – Wain Feb 27 '14 at 10:58
  • Sorry, my error was related to something else. Your solution worked. – Rui Feb 27 '14 at 14:59