import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class NovelRankModel { NovelRankModel({ required this.id, required this.lastUpdateTime, required this.name, required this.types, required this.cover, required this.authors, required this.lastUpdateChapterName, required this.top, required this.subscribeAmount, }); factory NovelRankModel.fromJson(Map json) { final List? types = json['types'] is List ? [] : null; if (types != null) { for (final dynamic item in json['types']!) { if (item != null) { types.add(asT(item)!); } } } return NovelRankModel( id: asT(json['id'])!, lastUpdateTime: asT(json['last_update_time'])!, name: asT(json['name'])!, types: types!, cover: asT(json['cover'])!, authors: asT(json['authors'])!, lastUpdateChapterName: asT(json['last_update_chapter_name'])!, top: asT(json['top'])!, subscribeAmount: asT(json['subscribe_amount'])!, ); } int id; int lastUpdateTime; String name; List types; String cover; String authors; String lastUpdateChapterName; int top; int subscribeAmount; @override String toString() { return jsonEncode(this); } Map toJson() => { 'id': id, 'last_update_time': lastUpdateTime, 'name': name, 'types': types, 'cover': cover, 'authors': authors, 'last_update_chapter_name': lastUpdateChapterName, 'top': top, 'subscribe_amount': subscribeAmount, }; }