我试图在objective-c中从UIViewcontroller获取json数据。但它没有改变视图中的任何内容。
我该怎么办?
- (void)api {
NSLog(@"test");
AFSecurityPolicy *securityPolicy = [[AFSecurityPolicy alloc] init];
[securityPolicy setAllowInvalidCertificates:YES];
NSString *urlPath = [NSString stringWithFormat:@"http://test.com/api/index.php"];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"process":@"musteri_detay",@"id": self.customerId,@"where":@""};
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
[manager setSecurityPolicy:securityPolicy];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:urlPath parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSString *string = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSError *error = nil;
NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
self.customerCards = [NSMutableArray array];
NSArray *customersArray = [dataDictionary objectForKey:@"musteri_list"];
for (NSDictionary *customersDictionary in customersArray) {
ApiClass *customer = [ApiClass customersWithTitle:[customersDictionary objectForKey:@"adi"]];
customer.tel = [customersDictionary objectForKey:@"tel1"];
customer.grubu = [customersDictionary objectForKey:@"grubu"];
customer.adres = [customersDictionary objectForKey:@"adres"];
NSNumber *customerType = [customersDictionary objectForKey:@"kayit_tipi"];
/*
if (customerType == 1) {
customer.kayitTipi_string = @"Müşteri";
} else if (customerType == 2) {
customer.kayitTipi_string = @"Kişi";
} else if (customerType == 10) {
customer.kayitTipi_string = @"Bayi";
} else if (customerType == 20) {
customer.kayitTipi_string = @"Aday";
} else {
customer.kayitTipi_string = @"";
}
*/
[self.customerCards addObject:customer];
}
NSLog(@"Get data %@",dataDictionary);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
这是getDetails。
-(void) getDetails {
ApiClass *customers = [self.customerCards objectEnumerator];
//self.kayitTipi.text = customers.kayitTipi_string;
self.Adi.text = customers.adi;
self.faliyetAlani.text = customers.grubu;
}
这是我的viewDidLoad方法。
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"ID: %@",self.customerId);
[self api];
[self getDetails];
// Do any additional setup after loading the view.
}
当我开始调试它的api方法时。[manager POST:urlPath parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
在这一行之后它继续方法结束。然后再去viewdidload.And去getdetails方法。转回api方法。并获取数据。但它没有改变任何东西。