问题
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