0
我想使用RKObjectMapping執行對象映射。使用RKObjectMapping嵌套映射
這裏是我的JSON的示例:
{
"notification": {
"created_at": "2012-10-23T02:43:43-04:00",
"delivered": true,
"id": 3915,
"missed": false,
"rejected": false,
"search_request_id": 360,
"bid": {
"bid_type": "none",
"bid_type_values": null,
"comment": "hi\n",
"created_at": "2012-10-23T02:43:54-04:00",
"delivered": true,
"delivery_type": "email",
"id": 268,
"has_chat_session": true,
},
"search_request": {
"created_at": "2012-10-23T02:43:42-04:00",
"customer_id": 6,
"id": 360,
"latitude": "40.7536854",
"location": "10001",
"longitude": "-73.9991637",
}
}
我已經使用jsonlint驗證了JSON,它是有效的。
這是我的映射。
RKObjectMapping *bidMapping = [RKObjectMapping mappingForClass:[Bid class]];
[bidMapping mapKeyPath:@"comment" toAttribute:@"comment"];
[bidMapping mapKeyPath:@"chat_session_id" toAttribute:@"chatSessionId"];
[objectManager.mappingProvider setMapping:bidMapping forKeyPath:@"bid"];
RKObjectMapping *searchRequestMapping = [RKObjectMapping mappingForClass:[SearchRequest class]];
[searchRequestMapping mapKeyPath:@"purpose" toAttribute:@"purpose"];
[searchRequestMapping mapKeyPath:@"customer_Id" toAttribute:@"customerId"];
[searchRequestMapping mapKeyPath:@"need" toAttribute:@"need"];
[objectManager.mappingProvider setMapping:searchRequestMapping forKeyPath:@"search_request"];
RKObjectMapping *notificationMapping = [RKObjectMapping mappingForClass:[Notification class]]; // have not mapped all the attributes.
[notificationMapping mapKeyPath:@"id" toAttribute: @"notificationId"];
[notificationMapping mapKeyPath:@"created_at" toAttribute:@"timestamp"];
[notificationMapping mapKeyPath:@"vendor_id" toAttribute:@"vendorId"];
[notificationMapping mapKeyPath:@"bid" toRelationship:@"bid" withMapping:bidMapping];
[notificationMapping mapKeyPath:@"search_request" toRelationship:@"search_request" withMapping:notificationMapping];
[objectManager.mappingProvider setMapping:notificationMapping forKeyPath:@"notification"];
該程序崩潰與斷言失敗,我無法調試時,我嘗試loadObjectsAtResourcePath。我也嘗試使用rootKeyPaths,但無濟於事。
有人可以幫我找到錯誤嗎?
謝謝!
ps:我想添加一個NSDictionary參數,文檔說使用appendQueryParams:params。但我收到警告說它已被棄用。我可以使用任何替代方案?
facepalm。我真的很愚蠢的錯誤。感謝你看到Rahul。乾杯! – Sohan
答案已過時 –
嗨,Alberto,你可以在這裏更新/發佈你的答案嗎?幾年前我已停止在iOS上工作,所以我不知道最近的變化。 –