网络:JSONKit框架的使用(天气预报)
2016-04-07 15:50
525 查看
#import "ViewController.h" #import "JSONKit.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; [self loadData]; } /** 1. 使用系统的解析json 效率明显比 jsonkit 会快,而且快很多 2. 如果旧项目中遇到使用解析json的第三方框架,尽量改成用系统的(AFNetworking 也是使用系统的) 3. 如果修改,可以按以下步骤: 3.1 删除JSONKit.h 和 JSONKit.m 3.2 哪里出错改哪里 */ - (void)JSONKit { NSURL *url = [NSURL URLWithString:@"http://localhost/demo.json"]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:10]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); for (int i = 0; i< 100 * 1000; i++) { id result = [[JSONDecoder decoder] objectWithData:data]; } NSLog(@"jsonkit %f",CFAbsoluteTimeGetCurrent() - start); }]; } - (void)loadData { NSURL *url = [NSURL URLWithString:@"http://localhost/demo.json"]; NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:10]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { CFAbsoluteTime start = CFAbsoluteTimeGetCurrent(); for (int i = 0; i< 100 * 1000; i++) { id result = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL]; } NSLog(@"jsonkit %f",CFAbsoluteTimeGetCurrent() - start); }]; } @end
相关文章推荐
- muduo网络库使用心得
- 神经网络研究,计算机是否能推理?
- 网络原理,以及对VMware Workstation虚拟网络VMnet0、VMnet1、VMnet8的图解
- TCP server 为什么一个端口可以建立多个连接?(网络讨论)
- 惠普打印机头部打印GET /Devmgmt/DiscoveryTree.xml HTTP/1.1 Host: 127.0.0.1:8080解决办法
- 太原网络营销师如何分析及考核百度竞价(SEM)人员
- iOS 使用AFNetWorking监听APP网络状态变化(可用于更改缓存策略、提示网络等)
- Http,Https (SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2 中文帮助文档
- [网络技术][转]网卡的offload概念
- Nginx + Tomcat + HTTPS 配置不需要在 Tomcat 上启用 SSL 支持
- 软件工程师的视角看网络(网络那点事)
- 通用套接字选项和TCP套接字选项
- tinyos学习笔记12--与网络相关的重要结构体索引
- Http协议与TCP协议简单理解
- 初识-----基于Socket的UDP和TCP编程及测试代码
- HTTP协议 简介
- WMware克隆虚拟机后出现网络无法连接的问题
- 从原理角度解析Android (Java) http 文件上传
- 解决android 5.0 webview不能加载http与https混合内容的问题
- 详解网络流量监控