Question

how should the mapping look like if I've got a JSON-response like this:

{
"persons":{
  "@size":"4",
  "person":[
     {
        "name":"John",
        "type":"Doe 1",
        "options":"some options"
     },
     {
        "name":"John",
        "type":"Doe 2",
        "options":"some other options"
     },
     {
        "name":"John",
        "type":"Doe 3",
     },
     {
        "name":"John",
        "type":"Doe 4",
     }
  ]
 }
 }

I already tried the following mapping, but it doesn't work:

RKManagedObjectMapping* personMapping = [RKManagedObjectMapping mappingForClass:[CDCustomFieldDefinition class]];
[personMapping mapKeyPath:@"label" toAttribute:@"label"];
[personMapping mapKeyPath:@"type" toAttribute:@"type"];
[personMapping mapKeyPath:@"options" toAttribute:@"options"];
personMapping.primaryKeyAttribute = @"label";

[[RKObjectManager sharedManager].mappingProvider setMapping:personMapping forKeyPath:@"persons"];

My objects array in didLoadObjects: is always empty... any ideas? Thanks a lot!

Was it helpful?

Solution

Should the keypath be

@"persons.person"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top