您可以從您的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
。
http://www.codeproject.com/Tips/622376/iOS-Soap-Webservice-Calling-and-Parsing-the-Resp check here – KethanKumar