在成功回调接入响应数据(Access Response Data in Success callba

2019-07-18 01:05发布

有什么办法来访问响应数据中签块使用对象管理的要求?

[objectManager postObject:[User class] path:@"/users" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
  NSLog(@"success");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
  NSLog(@"failure");
}];

好像应该有某种方式来使用映射或操作以获取这些信息,也许NSData的什么的。

Answer 1:

你可以从RKObjectRequestOperation *操作此信息

operation.HTTPRequestOperation.response
operation.HTTPRequestOperation.responseData
operation.HTTPRequestOperation.responseString


Answer 2:

试试这个

[objectRequestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {

// parse the response---       
 NSDictionary *myDic = [NSJSONSerialization JSONObjectWithData:operation.HTTPRequestOperation.responseData options:NSJSONReadingMutableLeaves error:nil];
  NSLog(@"=======:%@",myDic);
   NSLog(@"MY email============ %@ ",[myDic objectForKey:@"Email"]);      
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        RKLogError(@"Operation failed with error: %@", error);
    }];


文章来源: Access Response Data in Success callback
标签: restkit