file - 从 s3 存储桶读取 json 文件
问题描述
“我在亚马逊 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();
});
解决方案
您需要创建数据模型,然后解析 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');
}
}
推荐阅读
- groovy - JUnit Assume.assumeNotNull 抛出空指针而不是跳过测试
- bash - 本地 `commit-msg` 不能与全局 `prepare-commit-msg` 一起使用
- swift - Xcode 9.4.1 Swift 4 - 将非原始集与包含 Int 的原始集进行比较
- java - java.sql.SQLException 时区
- ios - fastlane nuke 是否也会删除推送证书
- ios - 从情节提要添加的 tableview 上方的普通视图在运行的 iOS App 中不可见
- javascript - 即使变量具有值,Javascript 变量也不会附加到 HTML 元素
- ios - 如何在动作表样式的 UIAlertController 中有多个突出显示的颜色?
- firebase - 实时 Firebase 删除权限被拒绝
- sql - 将日期调整为列中的最小值