我在我的應用程序中使用Restkit。我在映射一對一關係時遇到問題。RestKit一對一的關係映射錯誤
我有兩個實體任務和TaskNote。以前,Task和TaskNote之間有一對多的關係,即一個任務可以有很多筆記。
此代碼工作正常,然後
NSDictionary *taskNoteObjectMapping = @{
@"noteID" : @"noteID",
@"taskID" : @"taskID",
@"time_stamp" : @"time_stamp",
@"noteText" : @"noteText",
@"note_user_phone_no" : @"note_user_phone_no",
@"note_username" : @"note_username"
};
RKEntityMapping *taskNoteEntityMapping = [RKEntityMapping mappingForEntityForName:@"TaskNote" inManagedObjectStore:managedObjectStore];
[taskNoteEntityMapping addAttributeMappingsFromDictionary:taskNoteObjectMapping];
taskNoteEntityMapping.identificationAttributes = @[@"noteID"];
[taskEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"taskNote" toKeyPath:@"taskNote" withMapping:taskNoteEntityMapping]];
但由於一些要求我必須任務和它的音符即一個任務之間切換一對多的關係,一個人能有一個音符。在這個改變之後,我的映射開始失敗。即當我使用NSLog觀察與它的任務關係注意它結果爲零。和RestKit被記錄在表格
"tasks":[
{
"taskID":248,
"listID":388,
"taskName":"Cure",
"taskSyncStatus":1,
"taskState":0,
"task_latitude":0,
"task_longitude":0,
"taskLog":[ ],
"taskComment":[ ],
"taskNote":[
{
"noteID":113,
"taskID":248,
"noteText":"Note from server",
"note_user_phone_no":"+100",
"note_username":"Myself",
"time_stamp":14130583
}
]
}
請指導我在做什麼錯在這裏這個錯誤
Failed transformation of value at keyPath 'taskNote' to representation of type 'TaskNote': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value '(
"<TaskNote: 0x17833a60> (entity: TaskNote; id: 0x17833aa0 <x-coredata:///TaskNote/t33EC8AB0-1E62-4041-8B91-4B57BC0474F74> ; data: {\n noteID = 113;\n noteText = \"Note from server\";\n \"note_user_phone_no\" = \"+923335729486\";\n \"note_username\" = Myself;\n task = nil;\n taskID = 248;\n \"time_stamp\" = 14130583;\n})"
)' to TaskNote: none of the 2 value transformers consulted were successful." UserInfo=0x166ba240 {detailedErrors=(
"Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 \"The given value is not already an instance of 'TaskNote'\" UserInfo=0x16628750 {NSLocalizedDescription=The given value is not already an instance of 'TaskNote'}",
"Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3000 \"Expected an `inputValue` of type `NSNull`, but got a `__NSArrayM`.\" UserInfo=0x166ba1e0 {NSLocalizedDescription=Expected an `inputValue` of type `NSNull`, but got a `__NSArrayM`.}"
的JSON映射爲。如何映射一對一的關係。更改模型後,我還生成了實體任務和TaskNote的新子類。
如果需要,我可以提供更多信息。
什麼是類型/類taskNote'場的'現在的.h文件和'xcdatamodel'? – 2015-03-03 09:22:04
@AdilSoomro任務註釋目標實體是xcdatamodel中的TaskNote。和Task.h中一樣,它是TaskNote – Umair 2015-03-03 09:25:46