Blame view

lib/common/request/api_response/api_response_entity.dart 790 Bytes
056970d8   Key   feat: api
1
2
  import 'dart:convert';
  
8d581dd2   吴启风   feat: 给字段手写 JsonK...
3
4
  // No json_serializable here; keep a lightweight manual model to mimic old behavior
  import 'package:wow_english/generated/json/base/json_convert_content.dart';
056970d8   Key   feat: api
5
6
7
8
9
10
11
  class ApiResponse<T> {
    int? code;
    String? msg;
    T? data;
  
    ApiResponse();
  
8d581dd2   吴启风   feat: 给字段手写 JsonK...
12
13
14
15
16
17
18
19
20
    factory ApiResponse.fromJson(Map<String, dynamic> json) {
      final resp = ApiResponse<T>();
      resp.code = jsonConvert.convert<int>(json['code']);
      resp.msg = jsonConvert.convert<String>(json['msg']);
      if (json['data'] != null) {
        resp.data = JsonConvert.fromJsonAsT<T>(json['data']);
      }
      return resp;
    }
056970d8   Key   feat: api
21
  
8d581dd2   吴启风   feat: 给字段手写 JsonK...
22
23
24
25
26
    Map<String, dynamic> toJson() => <String, dynamic>{
          'code': code,
          'msg': msg,
          'data': data,
        };
056970d8   Key   feat: api
27
28
29
30
31
32
  
    @override
    String toString() {
      return jsonEncode(this);
    }
  }