json - 根据来自 URL "[FLUTTER] " 的 JSON 值进行重定向
问题描述
该 URL 具有 JSON 格式的返回值。这里的数据以 [{"operation":"0"}] 或 [{"operation":"1"}] 的形式出现。根据这里的值,我会在flutter中重定向到另一个站点。我无法解决问题。我试过的代码如下。
Future<List> login() async{
final response = await http.get("https://www.exampleurl.com");
var datauser = response.body;
if(datauser == 0 ){
print(datauser);
print(Text("Giriş Başarılı"),
);
}
else{
print(datauser);
print(Text(“Giriş Başarısız”));
}
}
我把它作为这段代码的输出。
颤振:[{“islem”:0}] 颤振:文本(“Giriş Başarısız”)
解决方案
You should use jsonDecode to access operation
value
Future<List> login() async{
final response = await http.get("https://www.exampleurl.com");
var datauser = jsonDecode(response.body)[0];
if(datauser['operation'] == 0 ){
print(datauser);
print(Text("Giriş Başarılı"),
);
}
else{
print(datauser);
print(Text(“Giriş Başarısız”));
}
}
do not forget to import
import 'dart:convert';
推荐阅读
- azure - 具有应用服务的 Azure 应用程序网关 - 使用应用服务的 https 侦听器
- rust - 我可以通过在两个异步接收器上调用 select 来错过一个值吗?
- html - 单击元素后,div内的标题会移到外面
- react-native - 如何使用谷歌登录从 AWS cognito 获取访问令牌
- python - 将查询集作为参数传递给 Django 中的 __in?
- cron - Ansible cronjob - 为文件名添加时间戳
- python - CVXPY 在基本二次问题上随机失败
- c# - 如何使用 LINQ 将另一个列表元素的列表类型属性的元素组合到一个列表中
- vscode-extensions - 从 Markdown 预览中的 VS Code Extension API 打开文件
- docker - 如何列出 docker 中所有已知的根密钥(Docker Content Trust)