Reputation: 29
Hi I'm trying to object map the following JSON:
{
"0":{
"chapter":"four",
"book":"Time Machine"
},
"1":{
"chapter":"nine",
"book":"Science"
},
"2":{
"chapter":"one",
"book":"Fiction Man"
},
"3":{
"chapter":"25",
"book":"Cars"
}
}
Code I am using:
RKObjectMapping *bookMapping = [RKObjectMapping mappingForClass:[Book class]];
[[RKObjectManager sharedManager].mappingProvider addObjectMapping:bookMapping];
[retailerMapping mapKeyPathsToAttributes:@"chapter", @"chapter",@"book", @"book", nil];
[objectManager.mappingProvider setMapping:bookMapping forKeyPath:@"0"];
This works for the first set, but will obviously skips 1, 2, and 3. How can I make this work?
Any help would be greatly appreciated.
Upvotes: 3
Views: 174
Reputation: 5032
If you have control over the structure of the JSON change it to be an array in place of a dictionary. Otherwise you may try mapKeyPath to key.attribute, for example 0.chapter
Example of JSON:
{chapters:[
{
"chapter":"four",
"book":"Time Machine"
},
{
"chapter":"nine",
"book":"Science"
},
{
"chapter":"one",
"book":"Fiction Man"
},
{
"chapter":"25",
"book":"Cars"
}
]
}
Upvotes: 1