URLConnection 数据解析

时间:2018-12-08 08:38:48
【文件属性】:
文件名称:URLConnection 数据解析
文件大小:37KB
文件格式:ZIP
更新时间:2018-12-08 08:38:48
URL iOS URLConnection 数据解析 数据的同步请求 数据的异步请求 #pragma mark -- 异步Block - (void)buttonBlock:(UIButton *)sender { NSLog(@"异步Block"); // 1. 创建网址 NSString *string = kTtpodHomPageURL; NSURL *url = [NSURL URLWithString:string]; // 2.设置网络请求 NSURLRequest *requst = [NSURLRequest requestWithURL:url]; // 建立异步连接,通过Block接受数据 [NSURLConnection sendAsynchronousRequest:requst queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { if (!connectionError) { //data 就是网络请求返回的数据 // 数据处理 id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"%@", result); } }]; NSLog(@"同步?异步?"); }
【文件预览】:
UI_URLConnection
----.DS_Store(6KB)
----UI_URLConnection.xcodeproj()
--------project.xcworkspace()
--------xcuserdata()
--------project.pbxproj(20KB)
----UI_URLConnectionUITests()
--------UI_URLConnectionUITests.m(1KB)
--------Info.plist(733B)
----UI_URLConnection()
--------ViewController.m(9KB)
--------Info.plist(2KB)
--------main.m(333B)
--------URLManager.h(611B)
--------Base.lproj()
--------ViewController.h(219B)
--------AppDelegate.h(276B)
--------Assets.xcassets()
--------AppDelegate.m(2KB)
----UI_URLConnectionTests()
--------Info.plist(733B)
--------UI_URLConnectionTests.m(925B)

网友评论