Reputation: 7930
I have a mapped (not managed) object in restkit:
@interface SynchObj : NSObject
@property (nonatomic, copy) NSString *event_data_c;
@property (nonatomic, copy) NSData *fields;
@end
....
mappingDict = @{@"event_data_c" :@"event_data_c",
@"fields" :@"fields",
};
responseMapping = [RKObjectMapping mappingForClass:[SynchObj class]];
[responseMapping addAttributeMappingsFromDictionary:mappingDict];
Now, when I receive the response :
response.body={"response":{"event_data_c":"2013-12-31 12:12:43":161,"server_id":77,"fields":{"nome":"pippo","cognome":"pippo"},"queue":""}}
In the success block of RestKit operation request I do:
SynchObj *item = mappingResult.firstObject;
NSDictionary *JSON =
[[NSJSONSerialization JSONObjectWithData: item.fields
options: kNilOptions
error: &e] objectForKey:@"response"];
NSLog(@"WS: mapped response %@",JSON );
but the JSON dictionary is always null. I can see however that item.fields is not null. What I am missing?
Upvotes: 1
Views: 250
Reputation: 119031
Change your property to:
@property (nonatomic, copy) NSDictionary *fields;
(assuming that it is always a dictionary).
Then RestKit will unpack the JSON for you and store it directly so you don't need to do any subsequent manipulation in the success
block.
Upvotes: 1