How can I to load and query local json data in Flu

2020-07-09 03:10发布

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",
}

1条回答
Bombasti
2楼-- · 2020-07-09 03:48

add your JSON file to the pubspec.yaml

  assets:
    - assets/config.json

and then you can use rootBundle to load it

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

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

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

查看更多
登录 后发表回答