【发布时间】:2013-10-12 10:26:06
【问题描述】:
我用过这个article!了解神奇记录中的数组导入包装器。 我想使用 dataKeyPath 支持在我的模型中直接加载关联的图像 URL。
json入口示例:
{
"attachments": [
{
"id": 1,
"url": "http://www.website.net/uploads/2013/10/image.png",
"title": "imageTitle",
"mime_type": "image/png",
"images": {
"full": {
"url": "http://www.website.net/uploads/2013/10/image-540x401.png",
"width": 540,
"height": 401
},
"thumbnail": {
"url": "http://www.website.net/uploads/2013/10/image-150x150.png",
"width": 150,
"height": 150
}
}
}
]
}
核心数据映射
在我的核心数据模型中,我使用带有属性 imageFull 的模型附件,该属性与值为“images.full.url”的“mappedKeyName”相关联。
导入时崩溃
定义完图像后,所有内容都已正确导入。问题是当我有这个时:
{
"attachments": [
{
"id": 1,
"url": "http://www.website.net/uploads/2013/10/image.png",
"title": "imageTitle",
"mime_type": "image/png",
"images": {
}
}
]
}
在这种情况下,我有一个错误:
Unacceptable type of value for attribute: property = "imageFull"; desired type = NSString; given type = __NSArrayI;
在此方法中尝试映射值时:
- (void) MR_setAttributes:(NSDictionary *)attributes forKeysWithObject:(id)objectData
问题在于,它不是返回空字符串或 nil,而是返回空图像数据。
你认为我的加载方式是错误的吗?还有其他方法吗?还是我必须手动完成?
感谢您的帮助:)
【问题讨论】:
标签: ios magicalrecord