import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class NewsStatModel { NewsStatModel({ required this.commentAmount, required this.moodAmount, required this.rowPicUrl, required this.title, }); factory NewsStatModel.fromJson(Map json) => NewsStatModel( /// DMZJ后端是真混乱... commentAmount是string,mood_amount是int commentAmount: int.tryParse(json['comment_amount'].toString()) ?? 0, moodAmount: int.tryParse(json['mood_amount'].toString()) ?? 0, rowPicUrl: asT(json['row_pic_url'])!, title: asT(json['title'])!, ); int commentAmount; int moodAmount; String rowPicUrl; String title; @override String toString() { return jsonEncode(this); } Map toJson() => { 'comment_amount': commentAmount, 'mood_amount': moodAmount, 'row_pic_url': rowPicUrl, 'title': title, }; }