MagicalRecord importFromObject:JSON with dictionary? [英] MagicalRecord importFromObject: JSON with dictionary?

查看:181
本文介绍了MagicalRecord importFromObject:JSON with dictionary?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析了以下格式的JSON:

I'm parsing some JSON which comes to me in this format:

{
dataId = "823o7tr23d387g";
category = "link";
details = {
    text = "Some text associated with the link";
    url = "http://www.url.com";
    thumbnail_url = "http://www.url.com/picture.jpeg";
};
source = "CNN";
},
{
...
},

MagicalRecord有一个伟大的导入方法: +(id)importFromObject:(id)data; 但它支持JSON字典内的字典, details {} 到相应的属性?

MagicalRecord has a great importing method: + (id) importFromObject:(id)data; but does it support dictionaries inside the JSON dictionary so that it can automatically map the details {} to the appropriate properties?

有没有命名约定或者我需要使用? / p>

Is there a naming convention or something I will need to use?

推荐答案

查看有关使用MagicalRecord自动导入JSON的文章,特别是数据keypath支持部分

Check out this article about using MagicalRecord to automatically import JSON, specifically the data keypath support section

http://www.cimgf .com / 2012/05/29 / importing-data-made-easy /


/ strong>

Data Keypath Support

键值编码是Objective C中一个通用且有效的工具。
MagicalImport允许您访问一些功能
将keysPath指定为mappedKeyName的一部分。如果你熟悉
与KVC,这应该是一个相当简单的功能,
Magicalmport将这些指定的键传递给KVC方法在
覆盖下。 Keypath支持允许您将数据映射到可能
与数据模型没有完全相同层次结构的实体。例如,
数据实体可以存储纬度和经度,但是源数据
看起来更像这样:

Key Value Coding is a common and effective tool in Objective C. MagicalImport gives you access to some of this power by allowing you to specify keyPaths as part of a mappedKeyName. If you’re familiar with KVC, this should be a fairly straightforward feature as Magicalmport passed these specified keys to the KVC methods under the covers. Keypath support allows you to map data to an entity that may not have exactly the same hierarchy as the data model. For example, a data entity may store latitude and longitude, but the source data looks more like this:

{
  "name": "Point Of Origin",
  "location":
  {
    "latitude": 0.00,
    "longitude": 0.00
  }
}

在这种情况下,我们可以指定为我们的数据导入关键路径,
location.latitude和location.longitude在我们的mappedKeyName
配置中挖掘嵌套数据结构,并将这些
值专门导入我们的核心数据实体。

In this case, we can specify as our data import key paths, location.latitude and location.longitude in our mappedKeyName configuration to dig into the nested data structure and import those values specifically into our core data entity.

这篇关于MagicalRecord importFromObject:JSON with dictionary?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆