【问题标题】:Reading a json file from s3 bucket从 s3 存储桶中读取 json 文件
【发布时间】:2019-05-27 10:52:36
【问题描述】:

“我在亚马逊 s3 存储桶上有一个带有 url 的文件,该文件是 json 格式,我想读取该文件并将其存储在颤振列表中”

HttpClient().getUrl(Uri.parse("mobile_app_air_ports.json"))
.then((HttpClientRequest request)=> request.close())
.then((HttpClientResponse response){
Future<List<String>> 
test=response.transform(Utf8Decoder()).toList();
});

【问题讨论】:

    标签: file http flutter dart


    【解决方案1】:

    您需要创建数据模型,然后解析 JSON:

    import 'dart:convert';
    
    
    class YourDataModel {
      final String yourData;
    
      Post({this.yourData});
    
      YourDataModel.fromJson(Map<String, dynamic> json) {
        return YourDataModel(
          yourData: json['yourData'],
        );
      }
    }
    
    Future<List<String>> fetchData() async {
      final response =
          await http.get('mobile_app_air_ports');
    
      if (response.statusCode == 200) {
        // If server returns an OK response, parse the JSON
        return (json.decode(response.body) as List<dynamic>)
            .map<YourDataModel>((item) => YourDataModel.fromMap(item))
            .toList();
    
      } else {
        // If that response was not OK, throw an error.
        throw Exception('Failed to load post');
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 2021-07-24
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      相关资源
      最近更新 更多