I write an application for iphone in objective-c and wanna get data from json. but I get null from url, but url is correct and when I pass url to browser I see the json data. this is my IBAction method:
- (IBAction)checkMobileNumber:(id)sender {
NSString *prefix = self.prefixTextField.text;
NSString *number = self.numberTextField.text;
NSString *url =[NSString stringWithFormat:@"http://ift.tt/15Q9nsW", prefix, number];
NSURL *jsonURL = [NSURL URLWithString:url];
@try {
[[[NSURLSession sharedSession] dataTaskWithURL:jsonURL completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString* rawJSON = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError *err;
self.checkMobile = [[CheckMobileProviderModel alloc] initWithString:rawJSON error:nil];
if (err) {
NSLog(@"Unable to initialize PublicPhotosModel, %@", err.localizedDescription);
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"%@", self.checkMobile.response);
//NSLog(@"%@", self.checkMobile.fault[@"faultString"]);
});
}] resume];
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
}
}
what is wrong here? any help?
Aucun commentaire:
Enregistrer un commentaire