2014-06-16 32 views
0

我想映射属性到RESTKit没有嵌套KVC的类,没有太多的运气,即使响应包含值我仍然得到零我的值。映射从POST没有嵌套KVC的响应

我已经阅读了对象映射手册,并试图用路径模式没有路径模式等。有没有人有任何见解?

2014-06-16 15:58:07.162 game[5961:60b] T 

restkit.network:RKObjectRequestOperation.m:178 POST 'https://api.myURL.com/api/0_0_1/notify/player': 
request.headers= 
{ 
    Accept = "application/json"; 
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5"; 
    "Content-Type" = "application/json; charset=utf-8"; 
    "User-Agent" = "game/1470 (iPhone; iOS 7.1; Scale/2.00)"; 
} 
request.body= 
{ 
    "game":"539e75acadae8fb03900057e", 
    "to":"533bd7eb5317b88f61000006", 
    "message":"‎Ben Fowler is waiting for you to play the game", 
    "from":"5332b4f5edfc9beb7900004d" 
} 
2014-06-16 15:58:08.856 game[5961:5607] T restkit.network:RKObjectRequestOperation.m:248 POST 'https://api.myURL.com/api/0_0_1/notify/player' (200 OK/1 objects) [request=1.6911s mapping=0.0020s total=1.6989s]: 
     response.headers={ 
      Connection = "keep-alive"; 
      "Content-Length" = 42; 
      "Content-Type" = "application/json; charset=utf-8"; 
      Date = "Mon, 16 Jun 2014 07:58:09 GMT"; 
      "X-Powered-By" = Express; 
     } 
     response.body= 
     { 
      "result": 1, 
      "notify": "871720292" 
     } 

类映射

请求和响应从服务器

-(void)WtfGameNotifcationResponse 
{ 
RKObjectMapping *notifyMapping = [RKObjectMapping mappingForClass:[WTFGameNotification class]]; 

[notifyMapping addAttributeMappingsFromDictionary: 
@{ 
@"result" : @"result", 
@"notify" : @"notifyID", 
}]; 

RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:notifyMapping 
                         method:RKRequestMethodGET 
                        pathPattern:@"notify/player" 
                         keyPath:nil 
                        statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor]; 

}

有问题的类

@interface WTFGameNotification : NSObject 

@property (nonatomic,copy) NSString* to; 
@property (nonatomic,copy) NSString* from; 
@property (nonatomic,copy) NSString* gameID; 
@property (nonatomic,copy) NSString* message; 

@property (nonatomic,strong) NSNumber* result; 
@property (nonatomic,copy) NSString *notifyID; 

+ (WTFGameNotification*)Create; 

@end 

回答

0

看来,如果你想映射一个POST的响应是应该使用的方法和语法。

+ (void)SendNotification:(GameInfo*)gameInfo withMessage:(NSString*)message forView:(UIViewController*)view 
{ 
    WTFGameNotification *_wtfGameNotif = [WTFGameNotification Create]; 

    [_wtfGameNotif setTo:[gameInfo opponentWTFID]]; 
    [_wtfGameNotif setFrom:[PlayerWTFInfo Load]._wtfID]; 
    [_wtfGameNotif setGameID:[gameInfo gameID]]; 
    [_wtfGameNotif setMessage:message]; 

    if ([_wtfGameNotif to] && [_wtfGameNotif gameID]) 
    { 
     RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] appropriateObjectRequestOperationWithObject:_wtfGameNotif 
                                method:RKRequestMethodPOST 
                                 path:nil 
                               parameters:nil]; 
     RFResponse *r1 = [RFResponse new]; 
     operation.targetObject = r1; 

     [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) 
     { 
      if (r1.result.integerValue != 0) 
      { 
       [Utilities FacebookPostWithResult:@{@"fbId": r1.notify}]; 
      } 
     } 
     failure:^(RKObjectRequestOperation *operation, NSError *error) 
     { 
      DDLogError(@"POST REQUEST FAILED IN CONFIRMFOTOVC : %@",[error description]); 

      if (view) 
      { 
       [LoadingView PopToRootShutterCloseOnView:view willOpen:YES]; 
      } 
     }]; 

     [operation start]; 

    } 
    else 
    { 
     DDLogInfo(@"NO PLAYER ID"); 
    } 
} 
0

如果您发布对象到服务器,那么你必须将不匹配,因为它与method:RKRequestMethodGET链接到一个GET响应描述符。您需要将其更改为method:RKRequestMethodPOST

当使用@"notify/player"的路径模式时,基本URL应设置为https://api.myURL.com/api/0_0_1/,但它看起来不像这是您的问题。