How can I to load and query local json data in Flutter Mobile App

浪尽此生 提交于 2019-12-07 04:51:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!