将Dart模型嵌套到Json
我在我们的Dart/Flatter项目中使用SQLite,我有两个表,一个用于条目,另一个用于与该条目相关的照片 目前,我正在将条目转换为json,并通过将所有条目数据导出到外部文本文件将Dart模型嵌套到Json,json,flutter,dart,Json,Flutter,Dart,我在我们的Dart/Flatter项目中使用SQLite,我有两个表,一个用于条目,另一个用于与该条目相关的照片 目前,我正在将条目转换为json,并通过将所有条目数据导出到外部文本文件 List<Journal> entries = []; jsonFile.writeAsStringSync(journalToJson(entries) factory journal.fromJson(Map<String, dynamic> json) => journal
List<Journal> entries = [];
jsonFile.writeAsStringSync(journalToJson(entries)
factory journal.fromJson(Map<String, dynamic> json) => journal(
id: json["_id"],
title: json["title"],
description: json["description"],
timestamp: json["timestamp"],
emotion: json["emotion"],
mood: json["mood"],
score: json["score"].toDouble(),
);
Map<String, dynamic> toJson() => {
"_id": id,
"title": title,
"description": description,
"timestamp": timestamp,
"emotion": emotion,
"mood": mood,
"score": score,
};
我需要导出数据看起来像
Export{
int id;
String title;
String description;
int timestamp;
String emotion;
String mood;
double score;
PhotoModel photos;
}
我一直在用嵌套在json数据中的照片导出它时遇到问题
Export{
int id;
String title;
String description;
int timestamp;
String emotion;
String mood;
double score;
PhotoModel photos;
}