调用方法后调用 RKObjectLoaderDelegate 的什么方法- (RKObjectLoader *)postObject:(id<NSObject>)object delegate:(id<RKObjectLoaderDelegate>)delegate
?
一旦我的 POST 成功,我将尝试运行更多代码。
编辑(更多信息):
@Paul 提到的这两种方法都没有被调用,但是我的服务器对 POST 的解释有些正确,因为正在写入数据库。
在应用程序初始化期间,我正在执行以下操作:
// Grab the reference to the router from the manager
RKObjectRouter *router = [RKObjectManager sharedManager].router;
// Define a default resource path for all unspecified HTTP verbs
[router routeClass:[EventMessage class] toResourcePath:@"/events_messages/:idPrimaryKey"];
[router routeClass:[EventMessage class] toResourcePath:@"/event_messages" forMethod:RKRequestMethodPOST];
当我准备发布时,我正在这样做:
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[EventMessage class]];
[objectMapping mapKeyPath:@"user_id" toAttribute:@"userId"];
[objectMapping mapKeyPath:@"event_id" toAttribute:@"eventId"];
[objectMapping mapKeyPath:@"message" toAttribute:@"message"];
[[RKObjectManager sharedManager].mappingProvider registerMapping:objectMapping withRootKeyPath:@"event_message"];
[[RKObjectManager sharedManager] postObject:eventMessage delegate:self];
这是我在控制台中遇到的错误:
错误域=JKErrorDomain 代码=-1 "意外的令牌,想要 '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', ' “字符串”,“数字”。UserInfo=0x7b9f510 {JKAtIndexKey=0, JKLineNumberKey=1, NSLocalizedDescription=Unexpected token, 想要 '{', '}', '[', ']', ',', ':', 'true', 'false', 'null'、'"STRING"'、'NUMBER'.}