12

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

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

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

4

2 回答 2

32

您可以从 RKObjectRequestOperation *操作中获取此信息

operation.HTTPRequestOperation.response
operation.HTTPRequestOperation.responseData
operation.HTTPRequestOperation.responseString
于 2013-01-11T04:34:44.277 回答
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);
    }];
于 2013-11-22T12:53:32.947 回答