DataParser<T> class
abstract
数据解析器抽象类 用于将服务器返回的原始数据解析为目标类型
使用场景:
- DirectParser: 不处理,直接返回原始数据(默认)
- DataFieldParser: 从标准格式中提取 data 字段 { "code": 200, "data": {...} }
- ListDataParser: 解析列表数据
- CustomParser: 自定义解析逻辑
注意:
- DataParser 默认为 DirectParser(不处理)
- 如果使用 DataFieldParser 等解析器,建议将 ResponseInterceptor 的 autoParse 设置为 false
- 每个请求可以指定独立的 parser,也可以设置全局默认 parser
示例:
// 设置全局默认解析器
NetworkClient.instance.setDefaultParser(DataFieldParser<Map<String, dynamic>>());
// 为单个请求指定解析器
final data = await client.get<User>(
'/user/profile',
parser: CustomParser((json) => User.fromJson(json)),
);
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parse(
dynamic rawData) → T -
解析数据
rawData原始响应数据 返回解析后的目标数据 -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited