【发布时间】:2022-01-07 12:47:21
【问题描述】:
大家好,我想知道如何从下面这个 JSON 文件中的设备获取数据。
我的 JSON:
{
"status":"UPDATE",
"data":{
"version":"2",
"modDate":"2021-12-22T17:33:59+0100",
"languages":[
"DE",
"EN"
],
"devices":[
{
"id":126,
"uuid":"b9407f30-f5f8-466e-aff9-25556b57fe6d",
"ma":600,
"mi":33815
},
{
"id":129,
"uuid":"b9407f30-f5f8-466e-aff9-25556b57fe6d",
"ma":600,
"mi":28664
},
我的方法:
Future<void> getDaten() async {
final response =
await http.get(Uri.parse("https://blablabla.de/index.php?id=7&version=2"));
final extractedData = json.decode(response.body) as Map<String, dynamic>;
print(extractedData);
extractedData.forEach((id, data) {
print(id);
print(data["devices"]);
});
}
我尝试使用extractData["data"] 和其他东西,但它不起作用。
在这个实际代码中我得到了这个错误
E/flutter (19705): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
【问题讨论】:
标签: json flutter api http dart