博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016 - 1 - 23 json转模型 常用的第三方框架
阅读量:4680 次
发布时间:2019-06-09

本文共 2853 字,大约阅读时间需要 9 分钟。

一: 三个常用的框架

  1. Mantle 

  - 所有模型必须继承MTModel

  2. JSONModel

  - 所有模型必须继承JSONModel

  3.MJExtension

  - 不需要继承任何东西。

  - 代码:

 

////  TableViewController.m//  json////  Created by Mac on 16/1/23.//  Copyright © 2016年 Mac. All rights reserved.//#import "TableViewController.h"#import 
#import
#import "ZZVideo.h"#import
@interface TableViewController ()@property (nonatomic, strong) NSArray *videos;@end@implementation TableViewController- (void)viewDidLoad { [super viewDidLoad]; NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/video"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) { NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; self.videos = [ZZVideo mj_objectArrayWithKeyValuesArray:dic[@"videos"]]; // NSLog(@"%zd",_videos.count); [self.tableView reloadData]; }]; }#pragma mark - Table view data source- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {//#warning Incomplete implementation, return the number of sections return 1;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {//#warning Incomplete implementation, return the number of rows return self.videos.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"video"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; ZZVideo *video = self.videos[indexPath.row]; cell.detailTextLabel.text = [NSString stringWithFormat:@"视频时长: %ld",(long)video.length]; cell.textLabel.text= video.name; NSString *image = [@"http://120.25.226.186:32812" stringByAppendingPathComponent:video.image]; [cell.imageView sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:nil]; return cell;}#pragma mark - 代理- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ ZZVideo *video = self.videos[indexPath.row]; NSString *videoStr = [@"http://120.25.226.186:32812" stringByAppendingPathComponent:video.url]; MPMoviePlayerViewController *vc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoStr]]; [self presentViewController:vc animated:YES completion:nil]; }@end

 

  

二: 设计第三方框架需要考虑的地方

 1.侵入性:

   - 侵入性大就意味着项目很难离开这个框架

 2.易用性

   - 比如少量代码就可以实现很多功能

 3.扩展性

  - 很容易给框架增加新的功能

 

 

   

转载于:https://www.cnblogs.com/BJTUzhengli/p/5153834.html

你可能感兴趣的文章
Mysql全文索引
查看>>
推荐书?
查看>>
说说ID选择符、类选择符和HTML标记选择符的优先级顺序
查看>>
浅谈软件架构师的素质与职责
查看>>
Python生成器实现杨辉三角打印
查看>>
ElasticSearch集群搭建
查看>>
解决EntityFramework数据库无法自动迁移解决方法
查看>>
ElasticSearch 基本操作
查看>>
unity 中 Tilemap的使用 笔记
查看>>
sort()的多种用法
查看>>
UNIX C 文件权限 Part2_day01
查看>>
linux部署Oracle数据库--创建数据库
查看>>
[LeetCode] 148. Sort List 链表排序
查看>>
Java判断密码强度工具类
查看>>
阶段4-独挡一面\项目-基于视频压缩的实时监控系统\Sprint1-基于Epoll架构的采集端程序框架设计\第1课-Epoll机制精通...
查看>>
jmeter(四十四)常用性能指标分析
查看>>
6个出色的基于JQuery的Tab选项卡实例2010/01/29 16:261. jQuery 选项卡界面 / 选项卡结构菜单教程...
查看>>
F - 八苦を滅した尼公 POJ - 2763 线段树LCA
查看>>
通过jQuery源码学习javascript(一)
查看>>
源码阅读经验谈-slim,darknet,labelimg,caffe(1)
查看>>