利用NSURLConnection请求数据

// 0.请求路径

NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/video"];

// 1.创建请求对象

NSURLRequest *request = [NSURLRequest requestWithURL:url];

// 2.发送请求

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

// 解析JSON

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

// 获得视频的模型数组

self.videos = [XMGVideo objectArrayWithKeyValuesArray:dict[@"videos"]];

// 刷新表格

[self.tableView reloadData];  // 注意刷新表格必须在主线程

}];

你可能感兴趣的:(利用NSURLConnection请求数据)