123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import 'package:sport/bean/UpdateInfo.dart';
- import 'package:sport/bean/comment.dart';
- import 'package:sport/bean/comment_post.dart';
- import 'package:sport/bean/forum.dart';
- import 'package:sport/bean/game.dart';
- import 'package:sport/bean/game_record.dart';
- import 'package:sport/bean/game_record_sum.dart';
- import 'package:sport/bean/image.dart';
- import 'package:sport/bean/message.dart';
- import 'package:sport/bean/notice.dart';
- import 'package:sport/bean/post.dart';
- import 'package:sport/bean/post_user.dart';
- import 'package:sport/bean/rank_game_info.dart';
- import 'package:sport/bean/rank_info.dart';
- import 'package:sport/bean/share_info.dart';
- import 'package:sport/bean/sport_detail.dart';
- import 'package:sport/bean/sport_index.dart';
- import 'package:sport/bean/sport_step.dart';
- import 'package:sport/bean/sport_target.dart';
- import 'package:sport/bean/sport_target_index.dart';
- import 'package:sport/bean/sport_target_record.dart';
- import 'package:sport/bean/sport_target_today.dart';
- import 'package:sport/bean/user_friend.dart';
- import 'package:sport/bean/user_info.dart';
- class Converter {
- static T fromJson<T>(json) {
- if (json == null) return null;
- var name = T.toString();
- switch (name) {
- case "UserInfo":
- return UserInfo.fromJson(json) as T;
- case "RankInfo":
- return RankInfo.fromJson(json) as T;
- case "Forum":
- return Forum.fromJson(json) as T;
- case "Image":
- return Image.fromJson(json) as T;
- case "Post":
- return Post.fromJson(json) as T;
- case "Comment":
- return Comment.fromJson(json) as T;
- case "CommentPost":
- return CommentPost.fromJson(json) as T;
- case "PostUser":
- return PostUser.fromJson(json) as T;
- case "SportIndex":
- return SportIndex.fromJson(json) as T;
- case "SportTarget":
- return SportTarget.fromJson(json) as T;
- case "SportTargetToday":
- return SportTargetToday.fromJson(json) as T;
- case "SportTargetIndex":
- return SportTargetIndex.fromJson(json) as T;
- case "SportTargetRecord":
- return SportTargetRecord.fromJson(json) as T;
- case "GameRecordSum":
- return GameRecordSum.fromJson(json) as T;
- case "GameRecord":
- return GameRecord.fromJson(json) as T;
- case "SportDetail":
- return SportDetail.fromJson(json) as T;
- case "SportDetailSimple":
- return SportDetailSimple.fromJson(json) as T;
- case "RecordsTodaySum":
- return RecordsTodaySum.fromJson(json) as T;
- case "Notice":
- return Notice.fromJson(json) as T;
- case "UserFriend":
- return UserFriend.fromJson(json) as T;
- case "GameInfoData":
- return GameInfoData.fromJson(json) as T;
- case "RankInfoData":
- return RankInfoData.fromJson(json) as T;
- case "RankGameInfoData":
- return RankGameInfoData.fromJson(json) as T;
- case "UpdateInfo":
- return UpdateInfo.fromJson(json) as T;
- case "SportStep":
- return SportStep.fromJson(json) as T;
- case "Message":
- return Message.fromJson(json) as T;
- case "NewFriend":
- return NewFriend.fromJson(json) as T;
- case "MessageInstance":
- return MessageInstance.fromJson(json) as T;
- case "ChatMessageInstance":
- return ChatMessageInstance.fromJson(json) as T;
- case "ChatOnlineInfo":
- return ChatOnlineInfo.fromJson(json) as T;
- case "MessageUser":
- return MessageUser.fromJson(json) as T;
- case "MessagePostUser":
- return MessagePostUser.fromJson(json) as T;
- case "ShareInfo":
- return ShareInfo.fromJson(json) as T;
- case "Share":
- return Share.fromJson(json) as T;
- }
- return json as T;
- }
- static double toDouble(dynamic num) {
- if (num == null) return 0.0;
- return (num is int) ? num.toDouble() : (num is String) ? double.parse(num) : num;
- }
- static int toInt(dynamic num) {
- if (num == null) return 0;
- if (num is String) {
- try {
- return int.parse(num);
- } catch (e) {
- return 0;
- }
- } else {
- return num;
- }
- }
- }
|