I'm using RestKit into my iPhone application to load a list of countries. The problem is the elementToPropertyMappings method uses a dictionary to map each object. In my case I have an array of strings that I'd like to map to the name property on my Country class.
Anyone know how todo this?
elementToPropertyMappings
Must return a dictionary containing mapping from JSON element names to property accessors
- (NSDictionary *)elementToPropertyMappings Declared In RKObjectMappable.h
My JSON Data
["Argentina","Australia","Austria","Belgium","Bolivia","Brazil","Bulgaria","Canada","Cayman Islands","China","Costa Rica","Croatia","Czech Republic","Denmark","Ecuador","Ethiopia","F.Y.R.O. Macedonia","Finland","France","French Polynesia","Germany","Guam","Hong Kong SAR","Indonesia","Ireland","Israel","Italy","Japan","Latvia","Lithuania","Luxembourg","Malaysia","Malta","Mexico","Morocco","Netherlands","New Zealand","Nicaragua","Norway","Papua New Guinea","Peru","Poland","Portugal","Puerto Rico","Qatar","Romania","Russia","Singapore","Slovakia","Slovenia","South Africa","South Korea","Spain","Sweden","Switzerland","Taiwan","United Arab Emirates","United Kingdom","United States","Venezuela","Vietnam"]
UPDATE:
I figured out how to use the RKClient to make a request so the Mapping functionality is skipped. Now I need to figure out what class to use for JSON parsing. The yajl-objc parser looks great but I don't want to include another parser if it can be done with a lib from RestKit.
-(void)loadLocations
{
NSLog(@"loadLocations");
RKObjectManager *objectManager = [RKObjectManager sharedManager];
[[RKClient sharedClient] get:@"/locations/countries.json" delegate:self];
}
- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response {
NSLog(@"Loaded payload: %@", [response bodyAsString]);
// HOW CAN I PARSE THIS STRING INTO AN NSArray?
}