RestKit:JSON 映射不起作用
如果我有这样的 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:
中的我的对象数组始终为空..有什么想法吗?多谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
键路径应该是
Should the keypath be