import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class NovelRecommendModel { NovelRecommendModel({ required this.categoryId, required this.title, required this.sort, required this.data, }); factory NovelRecommendModel.fromJson(Map json) { final List? data = json['data'] is List ? [] : null; if (data != null) { for (final dynamic item in json['data']!) { if (item != null) { data.add(NovelRecommendItemModel.fromJson( asT>(item)!)); } } } return NovelRecommendModel( categoryId: asT(json['category_id'])!, title: asT(json['title'])!, sort: asT(json['sort'])!, data: data!, ); } int categoryId; String title; int sort; List data; @override String toString() { return jsonEncode(this); } Map toJson() => { 'category_id': categoryId, 'title': title, 'sort': sort, 'data': data, }; } class NovelRecommendItemModel { NovelRecommendItemModel({ required this.cover, required this.title, this.subTitle, this.type, this.url, required this.objId, this.status, this.id, }); factory NovelRecommendItemModel.fromJson(Map json) => NovelRecommendItemModel( id: asT(json['id']), cover: asT(json['cover'])!, title: asT(json['title'])!, subTitle: asT(json['sub_title']), type: asT(json['type']), url: asT(json['url']), objId: asT(json['obj_id']), status: asT(json['status']), ); int? id; String cover; String title; String? subTitle; int? type; String? url; int? objId; String? status; @override String toString() { return jsonEncode(this); } Map toJson() => { 'cover': cover, 'title': title, 'sub_title': subTitle, 'type': type, 'url': url, 'obj_id': objId, 'status': status, }; }