json - Flutter应用程序中的Json解析花费了太多时间
问题描述
我有一个包含大约 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);
}
我想知道是否有任何替代方法可以这样做。
解决方案
你确定是解码需要时间而不是通过网络传输这个巨大的文件吗?
推荐阅读
- java - 为什么我们不在 lamnda 表达式中使用参数类型?
- google-cloud-platform - 如何在 bigquery 中下载大结果
- javascript - 返回重复数
- python - python按字符串匹配模式对列表项进行分组
- c - For循环在不应该的时候向后打印,解决方案有什么输入吗?
- python - 如何将 JSON 数据从 postman 推送到 django 框架
- angular - 对 WordPress 网站的 Angular HTTP 请求
- ruby - RubyMine 在 Ubuntu 上找不到 Ruby SDK
- python-3.x - 在python pandas的数据库表中一一加载相同的数据文件
- python - 如何在每次调用函数时缓存函数结果并更新缓存值?