2014-06-09 71 views
0

我需要連接到肥皂web服務。我從來沒有這樣做,而且據我所知,我需要使用user_nameuser_password創建會話。當會話成功時,我需要下載一些JSON對象。我選擇了AFNetworking這種網絡服務,但它似乎谷歌不能幫助我,因爲我不知道從哪裏開始。有人能幫我嗎?AFNetworking和肥皂會議

我試圖用AFHTTPRequestOperation創建會話,並且響應很好,但是如何繼續?如何下載我想要的?

+0

http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Resp check here – KethanKumar

回答

0

您可以從您的json對象獲取的所有數據是這樣的:

NSURL *url = [NSURL URLWithString:@"http://www.website/url"]; 

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; 

operation.responseSerializer = [AFJSONResponseSerializer serializer]; 
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { 

    // Here you are parsing your data 
    // The following sample fetch data from: 
    // { 
    //  status: 1 
    //  array: { 
    //   user: "user"; 
    //   password: "password"; 
    //  } 
    // } 
    NSDictionary *fullResponse = [[NSDictionary alloc] init]; 
    fullResponse = responseObject; 

    if ([[fullResponse objectForKey:@"status"] intValue] == 1) { 
     NSDictionary *array = [[NSDictionary alloc] init]; 
     array = [fullResponse objectForKey:@"array"]; 

     NSString *userName = [array objectForKey:@"user"]; 
     NSString *userPassword = [array objectForKey:@"password"];  
    } 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

    NSLog(@"Request Failed: %@, %@", error, error.userInfo); 

}]; 

[operation start]; 

還要注意的是,如果你的JSON對象包含任何array,你應該將它們存儲在NSArray(或NSMutableArray),而不是NSDictionary