问题
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:
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
来源:https://stackoverflow.com/questions/51360481/how-can-i-to-load-and-query-local-json-data-in-flutter-mobile-app