#import "ViewController.h"
#import "YYModel.h"
#import "Person.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// 有时候一个json可能返回四五个模型的数据
// 需要判断是哪个key
//
// NSDictionary *dict = @{
// @"name":@"张三",
// @"age":@20,
// @"id":@"12345",
// @"book":@{
// @"name":@"iOS开发"
//
// }
// };
//
// Person *person = [Person yy_modelWithJSON:dict];
//
//
// NSLog(@"%@",person);
// 加载数据
NSString *path = [[NSBundle mainBundle]pathForResource:@"data.json" ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:path];
NSArray *users = [NSArray yy_modelArrayWithClass:[Person class] json:data];
// 转成 数组
// 遍历数组
// 创建一个可变数组
// 创建一个模型
// 判断如果key 是 book 再来判断一个book模型
NSLog(@"%@",users);
}
@end
网络:YYModel 使用(JSON到模型的转换)
最新推荐文章于 2024-08-09 07:42:24 发布