#import "YYModel.h"
使用YYModel把字典数组转模型数组的核心代码
- 参数1:要转成的模型类型
- 参数2:字典数组
- 结果:模型数组
self.modelArray = [NSArray yy_modelArrayWithClass:[NewsModel class] json:dictArr];
使用YYModel把字典数组转模型数组的完整逻辑
- (void)loadData {
NSURL *url = [NSURL URLWithString:@"http://news.coolban.com/Api/Index/news_list/app/2/cat/0/limit/20/time/1457168894/type/0?channel=appstore&uuid=19C2BF6A-94F8-4503-8394-2DCD07C36A8F&net=5&model=iPhone&ver=1.0.5"];
[[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSArray *dictArr = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
self.modelArray = [NSArray yy_modelArrayWithClass:[NewsModel class] json:dictArr];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
}];
}] resume];
}