iOS开发学习笔记(OC语言)——网络请求
作者:互联网
系统提供的方式
NSString *urlString = @"https://xxx.xxx.xxx/xxx";
NSURLSession *sharedSession = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [sharedSession dataTaskWithURL:[NSURL URLWithString:urlString] completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSError *jsonError;
NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
NSArray *arr = [jsonObj allKeys];
for (int i = 0; i < jsonObj.count; i++) {
NSLog(@"%@: %@", arr[i], [jsonObj objectForKey:arr[i]]);
}
}];
[dataTask resume];
第三方库方式
NSString *urlString = @"https://xxx.xxx.xxx/xxx";
[[AFHTTPSessionManager manager]GET:urlString parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"");
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}
];
标签:jsonObj,NSURLSessionDataTask,Nullable,xxx,iOS,arr,笔记,C语言,urlString 来源: https://www.cnblogs.com/lurenjiashuo/p/15925975.html