import 'dart:convert'; T? asT(dynamic value) { if (value is T) { return value; } return null; } class UserCommentItem { UserCommentItem({ required this.commentId, required this.content, required this.replyAmount, required this.likeAmount, this.originCommentId, required this.objId, required this.createTime, this.toCommentId, required this.objCover, required this.objName, this.pageUrl, this.mastercomment, }); factory UserCommentItem.fromJson(Map json) => UserCommentItem( commentId: asT(json['comment_id']) ?? 0, content: asT(json['content']) ?? '', replyAmount: asT(json['reply_amount']) ?? 0, likeAmount: asT(json['like_amount']) ?? 0, originCommentId: asT(json['origin_comment_id']), objId: asT(json['obj_id']) ?? 0, createTime: asT(json['create_time']) ?? 0, toCommentId: asT(json['to_comment_id']), objCover: asT(json['obj_cover']) ?? '', objName: asT(json['obj_name']) ?? '', pageUrl: asT(json['page_url']), mastercomment: json['masterComment'] == null ? null : UserMasterComment.fromJson( asT>(json['masterComment'])!), ); int commentId; String content; int replyAmount; int likeAmount; int? originCommentId; int objId; int createTime; int? toCommentId; String objCover; String objName; String? pageUrl; UserMasterComment? mastercomment; @override String toString() { return jsonEncode(this); } Map toJson() => { 'comment_id': commentId, 'content': content, 'reply_amount': replyAmount, 'like_amount': likeAmount, 'origin_comment_id': originCommentId, 'obj_id': objId, 'create_time': createTime, 'to_comment_id': toCommentId, 'obj_cover': objCover, 'obj_name': objName, 'page_url': pageUrl, 'masterComment': mastercomment, }; } class UserMasterComment { UserMasterComment({ required this.id, required this.content, this.senderUid, this.likeAmount, required this.createTime, this.replyAmount, required this.nickname, }); factory UserMasterComment.fromJson(Map json) => UserMasterComment( id: asT(json['id'])!, content: asT(json['content'])!, senderUid: asT(json['sender_uid']), likeAmount: asT(json['like_amount']), createTime: asT(json['create_time'])!, replyAmount: asT(json['reply_amount']), nickname: asT(json['nickname'])!, ); int id; String content; int? senderUid; int? likeAmount; int createTime; int? replyAmount; String nickname; @override String toString() { return jsonEncode(this); } Map toJson() => { 'id': id, 'content': content, 'sender_uid': senderUid, 'like_amount': likeAmount, 'create_time': createTime, 'reply_amount': replyAmount, 'nickname': nickname, }; }