How to map nested complex JSON objects and save them to core data?

吃可爱长大的小学妹 提交于 2020-01-02 15:47:49

问题


I'm having problem with mapping and saving complex nested JSON data to Core data objects. It's meant for reading the data in case of offline mode and caching. JSON also has codes, which represent an id of an object in code list. Nesting depth of object in JSON can be between 5-8 objects.

Example of such (simplified) JSON would be something like this (Person object): https://pastebin.com/nKSFa5cp

Example of code list for relatedPerson:

{
    "relatedPerson": [
        {
            "code": 1,
            "description": "Mom"
        },
        {
            "code": 2,
            "description": "Dad"
        },
        {
            "code": 3,
            "description": "Sister"
        }
    ]
}

Example of code list for telecomUse:

{
    "telecomUse": [
        {
            "code": 1,
            "description": "Home"
        },
        {
            "code": 2,
            "description": "Personal"
        },
        {
            "code": 3,
            "description": "Work"
        }
    ]
}

Example of code list for telecomSystem:

{
    "telecomSystem": [
        {
            "code": 1,
            "description": "Phone"
        },
        {
            "code": 2,
            "description": "Mobile phone"
        },
        {
            "code": 3,
            "description": "Email"
        }
    ]
}

How can I map this code list data to core data object (Person object), at mapping time, with all dependants? Should I save nested object as String and then always map it when i want to read it? Is there any other possibility than manual assigning of codelists and saving it after mapping? The perfect solution, would be an object which would contain all nested objects after mapping and saving. How can this be achieved?

Thanks for your answers

来源:https://stackoverflow.com/questions/49875784/how-to-map-nested-complex-json-objects-and-save-them-to-core-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!