gpt4 book ai didi

ios - 使用 Magical Record 在 NSDictionary 中导入数组

转载 作者:行者123 更新时间:2023-11-29 02:44:45 26 4
gpt4 key购买 nike

我正在使用 Magical Record 导入从网络服务返回的数据。以下是json

{
"notes": null,
"logged_on": "2014-08-08",
"updated_at": "2014-08-08T15:33:25-04:00",
"user_id": 876,
"url": "https://august.roundtriptohealth.com/entries/5006",
"is_logged": true,
"id": 5006,
"entry_recording_activities": [
{
"recording_activity_id": 1,
"updated_at": "2014-08-08T16:39:19-04:00",
"url": "https://august.roundtriptohealth.com/entry_recording_activities/5006",
"recording_activity": {
"type_of_prompt": "textbox",
"updated_at": "2014-07-10T15:55:14-04:00",
"options": [],
"regex_validation": {
"message": "Up to three digits",
"name": "three_digits",
"regex": "^(\\d){1,3}$",
"display": "0 to 999"
},
"url": "https://august.roundtriptohealth.com/recording_activities/1",
"name": "Exercise Minutes",
"id": 1,
"cap_value": 360,
"summary": null,
"created_at": "2013-11-01T11:50:36-04:00",
"content": "**30+ minutes = 1 point**\n\nChoose a physical activity that elevates your heart, increases your breathing, and can be sustained for 30 minutes or more.\n\nWhen you and your Travel Companion log this activity the **same day**, you earn a bonus point and can visit a new attraction.",
"cap_message": "You have exceeded the maximum number of minutes."
},
"entry_id": 5006,
"id": 5006,
"value": "37",
"created_at": "2014-07-14T23:41:04-04:00"
},
{
"recording_activity_id": 1,
"updated_at": "2014-08-08T15:33:24-04:00",
"url": "https://august.roundtriptohealth.com/entry_recording_activities/16131",
"recording_activity": {
"type_of_prompt": "textbox",
"updated_at": "2014-07-10T15:55:14-04:00",
"options": [],
"regex_validation": {
"message": "Up to three digits",
"name": "three_digits",
"regex": "^(\\d){1,3}$",
"display": "0 to 999"
},
"url": "https://august.roundtriptohealth.com/recording_activities/1",
"name": "Exercise Minutes",
"id": 1,
"cap_value": 360,
"summary": null,
"created_at": "2013-11-01T11:50:36-04:00",
"content": "**30+ minutes = 1 point**\n\nChoose a physical activity that elevates your heart, increases your breathing, and can be sustained for 30 minutes or more.\n\nWhen you and your Travel Companion log this activity the **same day**, you earn a bonus point and can visit a new attraction.",
"cap_message": "You have exceeded the maximum number of minutes."
},
"entry_id": 5006,
"id": 16131,
"value": "45",
"created_at": "2014-08-08T15:33:24-04:00"
},
{
"recording_activity_id": 37,
"updated_at": "2014-08-08T15:33:24-04:00",
"url": "https://august.roundtriptohealth.com/entry_recording_activities/16132",
"recording_activity": {
"type_of_prompt": "checkbox",
"updated_at": "2014-07-30T13:42:27-04:00",
"options": [],
"regex_validation": null,
"url": "https://august.roundtriptohealth.com/recording_activities/37",
"name": "Eat 2 Different Colored Fruit Servings",
"id": 37,
"cap_value": null,
"summary": "You’ll make a couple of colorful choices on this week’s Tour Bus.",
"created_at": "2013-11-08T10:17:55-05:00",
"content": "By spreading daily choices across the rainbow of colors, you&rsquo;ll get the best produce has to offer &mdash; vitamins, minerals, fiber, and phytochemicals &mdash; for better health and energy. Have at least 2 <a href=\"http://www.chow.com/assets/2011/05/FRUIT_VEG_SERVINGS.pdf\" target=\"_blank\">fruit servings (2 cups)</a>, each from a different color group: red, orange, yellow/white, green, and blue/violet.",
"cap_message": null
},
"entry_id": 5006,
"id": 16132,
"value": null,
"created_at": "2014-08-08T15:33:24-04:00"
}
],
"created_at": "2014-08-08T15:33:24-04:00"
}

我可以使用以下方法导入顶级对象:

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
if ([responseObject isKindOfClass:[NSArray class]]) {
[Entry importFromArray:responseObject inContext:localContext];
}
}];

但是,第二层(数组 entry_recording_activities 内)不导入。我已经在数据模型文件中声明了条目。名为“Entry”的顶级对象。你可以从图像中看到。 enter image description here
二级对象如下:
enter image description hererelatedByAttribute 和关系也已设置。那么如何将数据导入多个条目(从顶层对象到低层对象)?

最佳答案

单击事件属性。在您的 relatedByAttribute 下,添加“mappedKeyName”,并添加嵌套路径。在这种情况下,entry_recording_activities。

基本问题是您已经定义了如何自动连接数据,但没有告诉导入库数据相对于导入开始的位置。

关于ios - 使用 Magical Record 在 NSDictionary 中导入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25284917/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com