成功回调中的访问响应数据

时间:2013-01-09 22:18:41

标签: restkit

有没有办法使用对象管理器访问成功块中的响应数据?

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

似乎应该有一些方法可以使用映射或操作来获取此信息,如NSData或其他东西。

2 个答案:

答案 0 :(得分:32)

您可以从RKObjectRequestOperation *操作

获取此信息
operation.HTTPRequestOperation.response
operation.HTTPRequestOperation.responseData
operation.HTTPRequestOperation.responseString

答案 1 :(得分:6)

试试这个

[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);
    }];