Initial commit
This commit is contained in:
20
lib/core/utils/json_utils.dart
Normal file
20
lib/core/utils/json_utils.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'dart:convert';
|
||||
|
||||
class JsonUtils {
|
||||
JsonUtils._();
|
||||
|
||||
static List<dynamic> safeDecodeList(String? json) {
|
||||
if (json == null || json.isEmpty) return [];
|
||||
try {
|
||||
final decoded = jsonDecode(json);
|
||||
if (decoded is List) return decoded;
|
||||
return [];
|
||||
} catch (_) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
static String encodeList(List<Map<String, dynamic>> list) {
|
||||
return jsonEncode(list);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user