【发布时间】:2021-03-10 01:17:37
【问题描述】:
我正在练习颤振,我需要使用 JSON 格式的响应数据。这是我的 POST 请求:
final response = await http.post(url,
headers: {"Content-type": "application/json", "accept": "/"},
body: json.encode({
'username': id,
'password': pwd,
'deviceId': devid,
}));
if (response.statusCode == 200) {
check = true;
print("OK");
} else {
check = false;
print("NOT OK");
}
print(response.body);
}
还有我的用户数据类:
class userData {
String deviceId;
String accessToken;
String name;
String surname;
}
userData globaluserData;
这是两个单独的 .dart 文件。所以,在我的回复中,我得到了这些数据,但我怎样才能让它像 -globaluserData.name = response.name- 我做了一些研究,但老实说,我无法理解和适应我的项目的解决方案。 提前致谢!
【问题讨论】:
标签: json flutter dart httpresponse