RestKit:JSON映射不起作用 [英] RestKit: JSON mapping doesn't work
本文介绍了RestKit:JSON映射不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这样的JSON响应,则映射应如何:
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"];
我在didLoadObjects:
中的对象数组始终为空...有什么想法吗?非常感谢!
My objects array in didLoadObjects:
is always empty... any ideas? Thanks a lot!
推荐答案
键路径应为
@"persons.person"
这篇关于RestKit:JSON映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文