I have a JSON structure like this:
[
{
"id" : "1",
"name" : "Group 1"
},
{
"id" : "2",
"name" : "Group 2"
},
{
"id" : "3",
"name" : "Group 3"
}
]
Please pay attention it begins with [ and ends with ]. How to map this-like JSON to array of Group objects using RestKit 2?
I tried with classic:
RKObjectMapping* groupMapping = [RKObjectMapping mappingForClass:[Group class]];
[groupMapping addAttributeMappingsFromDictionary:@{
@"id" : @"groupID",
@"name" : @"name"
}];
return groupMapping;
Then I'm using RKMappingTest to verify mapping, but I'm usually getting error:
restkit.object_mapping:RKMappingOperation.m:440 Failed transformation of value at keyPath 'id' to representation of type 'NSString': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value...
After parsing of JSON with:
_parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"groups.json"];
_parsedJSON is an array of dictionaries.
NSStringtoNSNumber...NSStringtoNSNumber, but with the JSON structure. If a JSON would be in format like {"":[ <array of objects> ]} (pay attention at enclosing brackets{}), everything goes well.