kfromJson<T> method

T? kfromJson<T>(
  1. T fromJsonT(
    1. dynamic json
    )
)

json转T,T = 原始数据类型 or 自定义对象

  原始数据类型
  'abc'.kfromJson((json) => json as String?) => abc
  "1".kfromJson((json) => json as int?) => 1
  '1.0'.kfromJson((json) => json as double?) => 1.0
  'false'.kfromJson((json) => json as bool?) => false
  对象
  userStr.kfromJson((json) => User.fromJson(json)) => User对象

Implementation

T? kfromJson<T>(T Function(dynamic json) fromJsonT) {
  var file = this;
  if (file == null || file.isEmpty) {
    return null;
  }
  return fromJsonT(jsonDecode(file));
}