2012-04-05 129 views
2

我使用RestKit映射RestKit投递响应

NSString* path = [NSString stringWithFormat:@"myPathHere"]; 
    NSDictionary *params = [NSDictionary dictionaryWithKeysAndObjects:@"rating",[rating stringValue], nil]; 
    [[RKObjectManager sharedManager].client post:path params:params delegate:self]; 

服务器将与我的managedObject“项目”的更新版本响应张贴到URI。

我该如何去映射这个项目。我使用下面的委托方法吗?

- (void)request:(RKRequest *)request didLoadResponse:(RKResponse *)response{} 

我知道从这里我可以得到响应JSON值,但是如何将其更改为映射对象呢?

任何帮助,非常感谢。

谢谢!

回答

0

当我需要我的地图服务器对象我作出这样的要求:

 [[RKObjectManager sharedManager] 
     loadObjectsAtResourcePath:[qualifiedResourceURL 
            appendQueryParams:params] 
     delegate:self 
     ]; 

,然后将对象回来在这个方法:

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects 

我再发布更新对象与通知管理器

 [[NSNotificationCenter defaultCenter] postNotificationName:GotFotosInRegion_Fotos_Array_Response object:objects]; 

最好的文档是https://github.com/RestKit/RestKit/blob/master/Docs/Object%20Mapping.md

+0

如果我使用GET,但是我使用POST,这可以正常工作。如果你看applyQueryParams方法,它所做的就是把你的字典传入并用“?”将它附加到路径中。在中间。 – iDev 2012-04-06 15:23:59

+0

你可以设置你的RKObjectRouter为POST。像这样:router = [RKObjectRouter new]; [route route class:[CheckStatus class] toResourcePath:@“/ registration/rest/users/checkstatus”forMethod:RKRequestMethodPOST]; – 2012-04-06 15:39:06

+0

我试过这个,它似乎没有工作。我觉得我正在接近。 *(在下一条评论中)*将导致objectloader didloadobjects被调用bu对象数组为空。 – iDev 2012-04-06 21:26:15