惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
T
Tailwind CSS Blog
博客园_首页
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
J
Java Code Geeks
量子位
D
DataBreaches.Net
MongoDB | Blog
MongoDB | Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
C
Check Point Blog
V
Visual Studio Blog
H
Help Net Security
Recent Announcements
Recent Announcements
Engineering at Meta
Engineering at Meta

博客园 - 观海云不远

ChatView:把 ChatGPT / Claude 对话保存、分享和发布成独立网页 AI对普通人到底有什么用?这8个场景告诉你答案 用 AI 做点不一样的事:你出想法,我来实现 Python 调试工具PDB的基本使用 帮园子算账省钱 linux I/O性能优化 Linux内存问题排查工具 CPU优化方案 系统中出现大量不可中断进程和僵尸进程怎么办? CPU 使用率过高怎么办 CPU上下文切换 到底应该怎么理解“平均负载”? iOS开发学习笔记(OC语言)——block使用示例 iOS开发学习笔记(OC语言)——调起APP(URL Scheme) iOS开发学习笔记(OC语言)——文件基本操作 iOS开发学习笔记(OC语言)——底部tab栏 iOS开发学习笔记(OC语言)——线程安全的单例 iOS开发学习笔记(OC语言)——UIView和UIViewController生命周期 Jenkins安装配置回滚 Mac 下反编译Android APK
iOS开发学习笔记(OC语言)——网络请求
观海云不远 · 2022-02-23 · via 博客园 - 观海云不远

系统提供的方式

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) {

    }
];