MagicalRecord importFromObject: JSON with dictionary?

后端 未结 2 2026
南方客
南方客 2021-01-07 03:14

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

{
dataId = \"823o7tr23d387g\";
category = \"link\";
details = {
    text = \"Some text associated wi         


        
2条回答
  •  终归单人心
    2021-01-07 03:56

    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/

    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.

提交回复
热议问题