如何在flutter应用程序中插入数据库中的字符串列表,我尝试通过将json数组编码到字符串中将其保存为字符串数据类型,但是技能数组每次都需要显式解码,如下所示,每当我需要从数据库。
List<User> userResponse = await tempDatabase.allItems;
jsonData = Result.fromJson({
"name": userResponse[0].name,
"skills": jsonDecode(userResponse[0].skills)
});
这是我的 json 回复
{
"result": [
{
"name":"Sidhant Rajora",
"skills": [
"C++",
"Java",
"Python",
"React"
]
},
{
"name":"Adity Rajora",
"skills": [
"C++",
"Java",
"Python"
]
}
]
}
我有这种 JSON 响应,它创建的模型 PODO 就像
class UsersJson {
List<Result> result;
UsersJson({this.result});
UsersJson.fromJson(Map<String, dynamic> json) {
if (json['result'] != null) {
result = new List<Result>();
json['result'].forEach((v) {
result.add(new Result.fromJson(v));
});
}
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.result != null) {
data['result'] = this.result.map((v) => v.toJson()).toList();
}
return data;
}
}
class Result {
String name;
int id;
List<String> skills;
Result({this.name, this.skills});
Result.fromJson(Map<String, dynamic> json) {
name = json['name'];
skills = json['skills'].cast<String>();
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['name'] = this.name;
data['skills'] = this.skills;
return data;
}
}
现在我不确定将模型插入数据库并从数据库中取回的方法。我曾尝试使用 SQFLite 库以及 Moor 库(https://moor.simonbinder.eu)