mysql get_mysql的get请求

先把mysql的php接口定义为宏

#define  kSqlUrl @"http://localhost:8888/mysql.php"

.m文件

demo

@interface YcwViewController ()

{

NSMutableArray *array;

}

@end

- (void)viewDidLoad

{

[super viewDidLoad];

array = [NSMutableArray array];

NSURL *url = [NSURL URLWithString:kSqlUrl];

NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];

NSOperationQueue *queue = [[NSOperationQueue alloc]init];

[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

if (connectionError != nil) {

NSLog(@"请求失败!,%@",[connectionError localizedDescription]);

}

else

{

NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];

NSLog(@"%@",arr);

for (NSDictionary *dic in arr) {

Position *position = [[Position alloc]init];

position.name = [dic objectForKey:@"name"];

position.money = [dic objectForKey:@"award"];

position.place = [dic objectForKey:@"city"];

position.position_id = [dic objectForKey:@"id"];

[array addObject:position];

}

NSLog(@"%@",array);

[self.myTableView reloadData];

}

}];

self.myTableView.delegate = self;

self.myTableView.dataSource = self;

}

demo2

- (void)viewDidLoad

{

[super viewDidLoad];

NSString *path = [NSString stringWithFormat:@"http://localhost:8888/show.php?id=%@",self.position_id];   //get请求可以直接把数据跟在url地址后面

//其他步骤和网络请求一样

NSURL *url = [NSURL URLWithString:path];

NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];

NSOperationQueue *queue = [[NSOperationQueue alloc]init];

[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {         if (connectionError != nil) {             NSLog(@"请求失败!,%@",[connectionError localizedDescription]);         }         else         {             NSArray *arr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];             NSDictionary *dic = arr[0];             NSLog(@"%@",dic);                          self.myLabel.text = [NSString stringWithFormat:@"name = %@ city = %@ award = %@ company = %@ descripe = %@ education = %@ experience = %@ kind = %@ offer =%@",[dic objectForKey:@"name"],[dic objectForKey:@"city"],[dic objectForKey:@"award"],[dic objectForKey:@"company"],[dic objectForKey:@"descripe"],[dic objectForKey:@"education"],[dic objectForKey:@"experience"],[dic objectForKey:@"kind"],[dic objectForKey:@"offer"]];                      }     }];      //    Position *position = [array objectAtIndex:0]; //    self.myLabel.text  = [NSString stringWithFormat:@"%@ %@ %@ ",position.money,position.name,position.place]; }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值