【发布时间】:2021-01-07 18:16:36
【问题描述】:
我有一个包含大约 40,000 个条目的 json 文件。我试图在我的颤振应用程序中解析它。我正在获取 json 并将其成功转换为所需的模型。但问题是,加载时间过长。我的 json 文件存储在 Firebase 存储桶中。有没有其他方法可以快速加载?我正在考虑将数据存储在实时数据库中,但我相信它也会很快给出结果。任何建议都会很有帮助。
class CollegeCode {
final String college_code;
final String studentcode;
final String college_Name;
final String college_Location;
CollegeCode({this.college_code, this.college_Name, this.college_Location, this.studentcode});
factory CollegeCode.fromJson(Map<String, dynamic> json) =>
CollegeCode(
college_code: json['College Code'] ,
college_Location: json['Location'],
college_Name: json['College Name'],
studentcode: json['Student Code']
);
}
class GetList{
GetList({this.data});
List<CollegeCode> data;
factory GetList.fromJson(Map<String, dynamic> json) {
// print(json['CollegesList'].toString());
if(json != null){
return GetList(
data: List<CollegeCode>.from(
json["CollegesList"].map((x) => CollegeCode.fromJson(x))).toList() ?? [],
);
}
return GetList(data: []);
}
}
Future <List<CollegeCode>> parsePhotos(String responseBody) async{
if(responseBody.isNotEmpty) {
final parsed = await GetList.fromJson(json.decode(responseBody));
final datalist = parsed.data.toList();
return datalist;
}
}
Future<List<CollegeCode>> fetchPhotos(http.Client client) async {
final response =
await client.get(url of file in storage bucket');
// print(response.body);
return parsePhotos(response.body);
// return compute(parsePhotos, response.body);
}
我想知道是否有任何替代方法。
【问题讨论】: