JSONModel 简单例子
2015-07-21 20:03
726 查看
// ProductModel.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import "JSONModel.h" @interface ProductModel : JSONModel @property (nonatomic,strong)NSString<Optional> * id1; @property (nonatomic,strong)NSString<Optional> * name; @property (nonatomic,strong)NSString<Optional> * price; @end // ProductModel.m // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import "ProductModel.h" @implementation ProductModel +(JSONKeyMapper *)keyMapper{ return [[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"id1",@"sss":@"xxxxx"}]; } @end
// test1Model.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import "JSONModel.h" @protocol test2Model @end @interface test2Model : JSONModel @property (nonatomic,strong)NSString<Optional> * id1; @property (nonatomic,strong)NSString<Optional> * name; @property (nonatomic,strong)NSString<Optional> * price; @end @interface test1Model : JSONModel @property (nonatomic,strong)NSString<Optional> * order_id; @property (nonatomic,strong)NSString<Optional> * total_price; @property (nonatomic,strong)NSArray<test2Model,Optional> * product; @end // test1Model.m // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import "test1Model.h" @implementation test2Model +(JSONKeyMapper *)keyMapper{ return [[JSONKeyMapper alloc] initWithDictionary:@{@"id":@"id1"}]; } @end @implementation test1Model @end
// ViewController.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end // // ViewController.m // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All rights reserved. // #import "ViewController.h" #import "test1Model.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSDictionary *dic=[[NSDictionary alloc]init]; test1Model *model=[[test1Model alloc]initWithDictionary:dic error:nil]; /* @property (nonatomic,strong)NSString<Optional> * order_id; @property (nonatomic,strong)NSString<Optional> * total_price; @property (nonatomic,strong)NSArray<test2Model,Optional> * product; */ // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- js刷新窗口 (父窗口,以及点确定后的当前窗口) 一般用于页面数据刷新重新加载
- 实时显示裁剪的DEM生成的等高线
- javascript笔试面试题
- JavaScript继承方式详解
- avalon.js 多级下拉框实现
- JS的事件监听机制
- Extjs-Grid-动态生成columns
- [JSON] JSON入门指南
- maven 加入json-lib.jar 报错 Missing artifact net.sf.json-lib:json-lib:jar:2.4:compile
- js获取各种宽高方法
- Js_日期格式化
- 用UglifyJS2合并压缩混淆JS代码
- 详解js跨域问题
- javascript中的“向量”
- AgularJS中Unknown provider: $routeProvider解决方案
- javascript实现网页屏蔽Backspace事件,输入框不屏蔽
- angular js自学笔记(二)——作用域1.0
- Javascript里,想把一个整数转换成字符串,字符串长度为2
- 利用tween.js算法生成缓动效果
- Json解析工具Jackson(使用注解)