2016 - 1 - 23 json转模型 常用的第三方框架
一: 三个常用的框架
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 <UIImageView+WebCache.h>
#import <MediaPlayer/MediaPlayer.h>
#import "ZZVideo.h"
#import <MJExtension.h>
@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 ;
} - (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.扩展性
- 很容易给框架增加新的功能
2016 - 1 - 23 json转模型 常用的第三方框架的更多相关文章
- iOS开发常用的第三方框架
1. AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是G ...
- Swift 项目中常用的第三方框架
Swift 项目中可能用到的第三方框架 字数1004 阅读4091 评论17 喜欢93 这里记录下swift开发中可能用的框架 , 最近浏览了不少,积累在这里,以后用的时候方便查阅.顺便推荐给大家! ...
- 2016 - 1 - 23 json解析
一: json 1. 什么是json 1.1 json是一种轻量级的数据格式,一般用于数据交互. 1.2 服务器返回给客户端的数据,一般都是JSON或者XML格式(文件下载除外). 2. JS ...
- 探索ASP.NET MVC5系列之~~~4.模型篇---包含模型常用特性和过度提交防御
其实任何资料里面的任何知识点都无所谓,都是不重要的,重要的是学习方法,自行摸索的过程(不妥之处欢迎指正) 汇总:http://www.cnblogs.com/dunitian/p/4822808.ht ...
- SQL Server 2016原生支持JSON
转载原地址: http://www.cnblogs.com/lyhabc/p/4747694.html SQL Server 2005 开始支持 XML 数据类型,提供原生的 XML数据类型.XML ...
- Java基础-Java中23种设计模式之常用的设计模式
Java基础-Java中23种设计模式之常用的设计模式 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.设计模式分类 设计模式是针对特定场景给出的专家级的解决方案.总的来说设 ...
- Gson Json 序列号 最常用的功能 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Murano Weekly Meeting 2016.08.23
Meeting time: 2016.August.23 1:00~2:00 Chairperson: Kirill Zaitsev, from Mirantis Meeting summary: ...
- Django ORM (一) 创建数据库和模型常用的字段类型参数及Field 重要参数介绍
创建一个 Django 项目及应用 django-admin startproject orm cd orm python manage.py startapp app01 在 models.py 上 ...
随机推荐
- [windows][C++][库]遍历删除文件夹
#include"windows.h"#include"string.h" BOOL IsDirectory(const char *pDir) { ]; Ze ...
- size_t总结
1.sizeof返回的必定是无符号整形,在标准c中通过 typedef 将返回值类型定义为size_t. 若用printf输出size_t类型时,C99中定义格式符%zd;若编译器不支持可以尝试%u或 ...
- 2015弱校联盟(1) - I. Travel
I. Travel Time Limit: 3000ms Memory Limit: 65536KB The country frog lives in has n towns which are c ...
- noi 6045 开餐馆
题目链接:http://noi.openjudge.cn/ch0206/6045/ 解题报告:参考了konjac 蒟蒻的. 题意: 有N个地址,从中选一些开餐馆,要保证相邻餐馆的距离大于k.问最大利润 ...
- Flowplayer-Skin
SOURCE URL: https://flowplayer.org/docs/skinning.html Skinning with CSS3 Flowplayer skin design is C ...
- [问题2014A06] 解答
[问题2014A06] 解答 用反证法, 设存在 \(n\) 阶正交阵 \(A,B\), 使得 \[A^2=cAB+B^2,\,\,c\neq 0.\cdots(1)\] 在 (1) 式两边同时左乘 ...
- printf("%*s%s%*s",——)是什么?
我们可能知道scanf里用*修饰符,是起到过滤读入的作用.比如一个有三列数值的数据,我只想得到第2列数值,可以在循环里用scanf(“%*d%d%*d”, a[i])来读入第i行的第2个数值到a[i] ...
- LuaStudio 9.27 去10分钟退出暗桩板
http://bbs.pediy.com/showthread.php?p=1428203#post1428203
- Maven学习(一) -- 安装Maven及Eclipse中配置Maven
标签(空格分隔): 学习笔记 本文环境:Windows7, JDK1.7.0_76 安装及配置Maven环境变量 需要电脑中已经有Java环境 在控制台中输入:echo %JAVA_HOME%看是否能 ...
- 学习mongo系列(八)密码与权限
一.设置密码及用户角色[1] > db.createUser(... {... user: "maxh",... pwd: "123",... roles ...