2012-04-05 133 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