我正在解析一些以这种格式出现的 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/