@interface ClassModel : NSObject
@property(nonatomic,strong)NSString *img;
@property(nonatomic,strong)NSString *step;
@end
@interface DataModel : NSObject
@property(nonatomic,strong)NSArray *steps;
@property(nonatomic,strong)NSString *title;
@property(nonatomic,strong)NSString *tags;
@property(nonatomic,strong)NSString *imtro;
@property(nonatomic,strong)NSString *albums;
@end
@interface Data : NSObject
@property(nonatomic,strong)NSArray *data;
@end
@interface Model : NSObject
@property(nonatomic,strong)Data *result;
.m中
+(NSDictionary *)modelContainerPropertyGenericClass {
// value should be Class or Class name.
return @{@“steps” : [ClassModel class]};
}
@end
@implementation Data
+(NSDictionary *)modelContainerPropertyGenericClass {
// value should be Class or Class name.
return @{@“data” : [DataModel class]
};
}
@end
@implementation Model
+(NSDictionary *)modelContainerPropertyGenericClass {
// value should be Class or Class name.
return @{@“result” : [Data class]};
}
AFHTTPSessionManager *manger=[AFHTTPSessionManager manager];
manger.responseSerializer=[AFJSONResponseSerializer serializer];
[manger GET:@“http://apis.juhe.cn/cook/query?key=f39f197e0fae5489277675172b4cea90&menu=西红柿&rn=10&pn=3” parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@“网络请求成功”);
self.model=[Model yy_modelWithJSON:responseObject];
[self.tbv reloadData];
NSLog(@"%@",[self.model.result.data[0]albums]);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"网络请求失败");
}];
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.model.result.data.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
self.tbv.rowHeight=100;
TableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@“cell”];
if (cell==nil) {
cell=[[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@“cell”];
}
DataModel *mod=[self.model.result.data objectAtIndex:indexPath.row ];
[cell setModel:mod];
return cell;
}