123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- 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_add_entity.dart';
- import 'package:sport/bean/game_record.dart';
- import 'package:sport/bean/game_record_sum.dart';
- import 'package:sport/bean/hardware.dart';
- import 'package:sport/bean/image.dart';
- import 'package:sport/bean/jog/detail.dart';
- import 'package:sport/bean/jog/record.dart';
- import 'package:sport/bean/jog/sum.dart';
- import 'package:sport/bean/login.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/shop.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';
- import 'package:sport/bean/exer_index.dart';
- import 'package:sport/bean/achievement_rule.dart';
- import 'package:sport/bean/friend_list.dart';
- import 'package:sport/bean/friend_relation.dart';
- import 'package:sport/bean/game_record_history.dart';
- class Converter {
- static T? fromJson<T>(json) {
- if (json == null) return null;
- var name = T.toString();
- switch (name) {
- case "User":
- return User.fromJson(json) as T;
- 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;
- case "ShopIndex":
- return ShopIndex.fromJson(json) as T;
- case "ScoreList":
- return ScoreList.fromJson(json) as T;
- case "JogDetail":
- return JogDetail.fromJson(json) as T;
- case "JogSum":
- return JogSum.fromJson(json) as T;
- case "JogRecord":
- return JogRecord.fromJson(json) as T;
- case "ExerIndex":
- return ExerIndex.fromJson(json) as T;
- case "AchievementRule":
- return AchievementRule.fromJson(json) as T;
- case "FriendList":
- return FriendList.fromJson(json) as T;
- case "FriendRelation":
- return FriendRelation.fromJson(json) as T;
- case "GameRecordHistory":
- return GameRecordHistory.fromJson(json) as T;
- case "Hardware":
- return Hardware.fromJson(json) as T;
- case "LoginInfo":
- return LoginInfo.fromJson(json) as T;
- case "SportHistory":
- return SportHistory.fromJson(json) as T;
- case "GameAddEntity":
- return GameAddEntity.fromJson(json) as T;
- case "String":
- return "$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 v) {
- if (v == null) return 0;
- if (v is String) {
- try {
- return int.parse(v);
- } catch (e) {
- return 0;
- }
- } else if (v is double) {
- try {
- return v.toInt();
- } catch (e) {
- return 0;
- }
- } else if (v is int) {
- return v;
- } else if (v is num) {
- return v.toInt();
- }
- return 0;
- }
- }
|