fromJson<T> static method
JSON 字符串转为对象。
⚠️ 精度限制:底层 dart:convert 的 json.decode 会把 JSON 数字解析为
Dart 的 int/double。当整数大于 2^53(9007199254740992)时,可能因
浮点表示而丢失精度。如需精确的大整数,请在源头以字符串承载该字段,
再在 fromMap 内自行解析为 BigInt。
Implementation
static T? fromJson<T>(
String? jsonStr, T Function(Map<String, dynamic> map) fromMap) {
if (jsonStr == null || jsonStr.isEmpty) return null;
try {
final map = json.decode(jsonStr);
if (map is! Map<String, dynamic>) return null;
return fromMap(map);
} catch (e) {
logger.e('JSON 解析失败: $e, 数据: $jsonStr');
return null;
}
}