【发布时间】:2021-10-16 11:33:07
【问题描述】:
我编写了获取 Json 数据并放入 listPc 的代码。并编写了将值“hostName”从 listPc 添加到 pcBusy 列表的循环。但是我的代码只将值添加到第二个列表中,如果我在 pcBusy 列表重复中按 GetButton 值。我需要更新 pcBusy 列表,而不仅仅是添加相同的值。
如果我按两次按钮会打印:
[S14, S18, S19, S12, S02, V08, S01, O09, S14, S18, S19, S12, S02, V08, S01, O09]
感谢您的帮助!)
void fetchDataStandart() async {
final urlAuth =
Uri.parse('http://XXX.XX.XXX.XXX/api/usersessions/activeinfo');
final response = await http
.get(urlAuth, headers: <String, String>{'authorization': basicAuth});
if (response.statusCode == 200) {
List listPc = List.from(json.decode(response.body)['result']);
for (int i = 0; i < listPc.length; i++) {
pcBusy.add(listPc[i]['hostName']);
}
print(pcBusy);
} else {
throw Exception('Ошибка получения данных');
}
}
【问题讨论】:
标签: arrays json list flutter dart