2011-12-06 149 views
0

應該如何映射的樣子,如果我有一個JSON響應這樣的: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:總是空的......任何想法?非常感謝!

回答

3

的應該是的keyPath

@"persons.person" 
+0

非常感謝你,它的工作原理!我用'@「人/人」'嘗試過,但我從來沒有用點語法嘗試......謝謝! – swalkner

+0

@swalkner:幸運的猜測:) – JeremyP