2013-01-09 64 views
12

有什麼方法可以使用對象管理器訪問成功塊中的請求中的響應數據嗎?成功回調中的訪問響應數據

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

似乎應該有一些方法來使用映射或操作來獲取這些信息,也許NSData或其他東西。

回答

32

你可以從RKObjectRequestOperation *操作

operation.HTTPRequestOperation.response 
operation.HTTPRequestOperation.responseData 
operation.HTTPRequestOperation.responseString 
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); 
    }]; 
+0

容易,一旦你知道如何! – andygeers