懒加载中 把JSON文件转模型,复制给控制器的模型属性

来源:互联网 发布:深圳数据恢复公司 编辑:程序博客网 时间:2024/06/05 02:11
- (NSArray *)htmls{    if (_htmls == nil) {                // JSON文件的路径        NSString *path = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil];                // 加载JSON文件        NSData *data = [NSData dataWithContentsOfFile:path];                // 将JSON数据转为NSArray或者NSDictionary        NSArray *dictArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];                // 将字典转成模型        NSMutableArray *htmlArray = [NSMutableArray array];        for (NSDictionary *dict in dictArray) {            MJHtml *html = [MJHtml htmlWithDict:dict];            [htmlArray addObject:html];        }                _htmls = htmlArray;    }    return _htmls;}

0 0
原创粉丝点击