objective-c - RestKit:JSON 映射不起作用

标签 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: 中的对象数组总是空的……有什么想法吗?非常感谢!

最佳答案

keypath应该是

@"persons.person"

关于objective-c - RestKit:JSON 映射不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8403286/

相关文章:

iOS 框架问题 : Class is implemented in both

c# - Entity Framework : mapping tinyint to boolean

c# - 如何通过 AutoMapper 将匿名对象映射到类?

ios - 在 Objective C 中显示 MapKit "Map loading error"

iphone - 如何在 iphone 中使用 ZipArchive 压缩文件夹?

javascript - iOS:加载 javascript 并将其注入(inject)网页的最快方法?

ios - 地幔是否需要完全指定模型?

ios - 将自定义 UIView 添加到 UIScrollview - 如何计算位置、大小和处理缩放?

ios - 比较是否让快速进入?

ios - SpriteKit 混合目标 alpha