//网络请求
//1.生成URL
NSURL *url = [NSURL URLWithString:CQGETUEL];
//2.创建请求对象,绑定URL
NSMutableURLRequest *requst = [[NSMutableURLRequest alloc] initWithURL:url];
//3.发送请求
NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:nil error:nil];
NSLog(@"%@", data);
//JSon 解析
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSArray *arr = dic[@"news"];
self.data = [NSMutableArray array];
for (NSDictionary *dic in arr) {
News *news = [[News alloc] init];
[news setValuesForKeysWithDictionary:dic];
[self.data addObject:news];
}
//循环打印检查
for (News *news in self.data) {
NSLog(@"%@--%@--%ld", news.title, news.NId, news.sequence);
}
iOS网络编程:二、POST方式同步请求
最新推荐文章于 2022-08-17 14:38:53 发布