我想和POST方法的請求之後,我希望他們能夠返回JSON數據或NSDictionary
,但他們只能返回時,它成功的字符串AFNetworking POST無法返回JSON數據
像NSString *response = [operation responseString];
任何人都知道如何讓他們返回NSdictionary
而不是NSString
?
-(IBAction)SubmitLogin:(id)sender{
NSLog(@"Login");
// NSLog(@"%@",username);
//START FUNGSI UNTUK POST, PUT, DELETE
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:signinUrl];
[httpClient defaultValueForHeader:@"Accept"];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
@"someuser", @"username",
@"somepassword",@"password",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST"
path:@""
parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];
[operation setCompletionBlockWithSuccess:
^(AFHTTPRequestOperation *operation,
id responseObject) {
NSString *response = [operation responseString];
NSLog(@"response: %@",response);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", [operation error]);
}];
//call start on your request operation
[operation start];
謝謝你的回答和編輯我的問題,我的英語不好對不起。 – Zoro 2013-02-27 10:51:59
我沒有編輯你的問題Zoro,也不擔心你的英語,這是非常可以理解的。希望這一點的代碼可以幫助你一點,歡迎來到Stack Overflow :)。 – 2013-02-27 10:53:28