I receive JSON code that looks like this:
{
"rent": {
"items": [
],
"total": 0
},
"upcoming": {
"items": [
],
"total": 0
},
"watchnow": {
"items": [
],
"total": 0
}
}
I want the keys, i.e. "rent", "upcoming" and "watchnow" as a property on the mapped object, so I add a NSString property called searchSection to the class I'm using and then create this mapping:
RKObjectMapping *searchResultsMapping = [RKObjectMapping mappingForClass:[TDXSearchResults class]];
[searchResultsMapping addAttributeMappingFromKeyOfRepresentationToAttribute:@"searchSection"];
Shouldn't my mappingResult.array
then contain three TDXSearchResults objects, each with either "rent", "upcoming" or "watchnow" in its searchSection
property? I only get one TDXSearchResults in the array and this confuses me greatly.
You should only expect 1 result because your source data is only 1 object (and you must only have 1 response descriptor).
If you want 3 result objects then you should use either:
forceCollectionMapping
on the mappingitems
and each using a different keypath (rent / upcoming / watchnow).