如何在Flutter Mobile App中加载和查询本地json数据

5 json load flutter

这是我的关键:价值配对本地json.我需要加载,稍后我需要用于查询.那么,我如何在Flutter Mobile App中加载和查询本地json数据?

{
  "currency.01": "United State USD",
  "currency.17": "British Pound GBP",
  "currency.33": "Euro EUR",
}
Run Code Online (Sandbox Code Playgroud)

Rao*_*che 20

将您的JSON文件添加到 pubspec.yaml

  assets:
    - assets/config.json
Run Code Online (Sandbox Code Playgroud)

然后你可以rootBundle用来加载它

import 'dart:async' show Future;
import 'package:flutter/services.dart' show rootBundle;

Future<String> loadAsset() async {
  return await rootBundle.loadString('assets/config.json');
}
Run Code Online (Sandbox Code Playgroud)

还要看一下这个完整的例子, 并查询将你的JSON数据转换成LIST然后你有很多搜索方法,比如where方法