这是我的核心价值配对本地 json。我需要加载,稍后我需要用于查询。
那么,如何在Flutter移动应用中加载和查询本地json数据呢?
{
"currency.01": "United State USD",
"currency.17": "British Pound GBP",
"currency.33": "Euro EUR",
}
将您的 JSON 文件添加到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');
}
也看看这个完整的例子 https://github.com/nisrulz/flutter-examples/tree/master/load_local_json并为了查询将 JSON 数据转换为LIST https://docs.flutter.io/flutter/dart-core/List-class.html然后你就有很多搜索方法,比如where https://docs.flutter.io/flutter/dart-core/Iterable/where.html method
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)