encodeObject<T> method
将单个对象转为 JSON 字符串
Implementation
String? encodeObject<T>(T? obj, Map<String, dynamic> Function(T) toJson) {
if (obj == null) return null;
try {
return json.encode(toJson(obj));
} catch (e) {
logger.e('JSON 单个对象编码失败: $e');
return null;
}
}