objective-c - MagicalRecord importFromObject : JSON with dictionary?

标签 objective-c ios core-data magicalrecord

我正在解析一些以这种格式出现的 JSON:

{
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 自动导入 JSON 的文章,特别是数据键路径支持部分

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

Data Keypath Support

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
  }
}

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.

关于objective-c - MagicalRecord importFromObject : JSON with dictionary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12057495/

相关文章:

ios - SceneKit 3D 标记增强现实 iOS

ios - 以编程方式滑动 UIScrollView

ios - 混合和 super

ios - 如何在 "save"实体 View 中对 "master/parent"实体进行 "detail"(核心数据)?

iphone - 应用程序运行时替换 Core Data sqlite 文件,数据不更新

ios - AVAssetWriterInput 当前不支持 AVVideoScalingModeFit - IOS 错误

iphone - Xcode4 模板现在在 iVars 上使用下划线?

ios - app进入applicationDidEnterBackground后,我们应该怎么做才能运行NSoperationqueue?

ios - 我应该使用 NSDate 来跟踪到达时间和迟到时间吗?

ios - 将 persistenceStoreCoordinator sqlite 文件迁移到新名称