如何在Flutter Mobile App中加载和查询本地json数据 [英] How can I to load and query local json data in Flutter Mobile App
本文介绍了如何在Flutter Mobile App中加载和查询本地json数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的 key:value 配对本地json.我需要加载,以后再用于查询. 那么,如何在Flutter Mobile App中加载和查询本地json数据?
Here is my key:value paired local json. I need to load and later I need to use for query. So, how can I to load and query local json data in Flutter Mobile App?
{
"currency.01": "United State USD",
"currency.17": "British Pound GBP",
"currency.33": "Euro EUR",
}
推荐答案
将JSON文件添加到pubspec.yaml
add your JSON file to the pubspec.yaml
assets:
- assets/config.json
,然后您可以使用rootBundle
加载
import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;
Future<String> loadAsset() async {
return await rootBundle.loadString('assets/config.json');
}
还请看这个完整示例 然后将JSON数据转换为 LIST 有很多搜索方法,例如 where 方法
also take a look at this full example and for querying convert your JSON data into a LIST and then you have a lot of search methods like the where method
这篇关于如何在Flutter Mobile App中加载和查询本地json数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文