RestKit:JSON映射不起作用

时间:2011-12-06 16:25:14

标签: objective-c ios mapping restkit

如果我有这样的JSON响应,那么映射应该如何:

{
"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",
     }
  ]
 }
 }

我已经尝试过以下映射,但它不起作用:

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"];

didLoadObjects:中的我的对象数组总是空的......任何想法?非常感谢!

1 个答案:

答案 0 :(得分:3)

密钥路径应该是

@"persons.person"