flutter - 显示返回的 JSON
问题描述
我正在尝试在对话框中显示 JSON。无法找到删除显示的括号的方法。任何帮助都会很棒。
这是 JSON:
{
"status": false,
"comment": {
"email_id": [
"Email ID \"pixaflip.tech@gmail.com\" has already been taken."
],
}
}
这是我为在 Networkutils 类中提取 JSON 而实现的代码:
Future<User> createUser(String url,{Map body}) async{
return http.post(url,
body:body).then((http.Response response){
if (response.statusCode < 200 || response.statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
}
var extractdata = json.decode(response.body);
if(status == "false"){
Map comment = extractdata["comment"];
}
return User.fromJson(json.decode(response.body));
});
}
这就是我显示消息的方式:
Networkutils _networkUtils = new NetworkUtils.
var list = _networkUtils.comment.values.toList();
_showDialogue("Registration", "$list");
解决方案
你可以这样做..
_showDialogue("Registration", "${list[0][0]}");
两对方括号的原因_networkUtils.comment.values.toList()
是给你一个列表列表。因此,当您直接将其显示为字符串时,它会显示为 2 对括号,这表明它是一个列表列表。因此,当我们这样做时,list[0][0]
它会提取出内部第一个列表的第一项list
,这就是您要显示的内容。
推荐阅读
- javascript - this.winRef.nativeWindow.Razorpay 不是构造函数
- encryption - 如何解密每个加密元素都是 2 个字母的消息?
- javascript - 如何在 vue 中使用下载属性?
- javascript - 如何为文本字段实现正则表达式以在 Extjs 中一次允许一个逗号一个空格
- python - Pandas CSV 导入中二进制变量的最佳数据类型以减少内存使用
- c - 并发线程和数据竞争
- java - Draw on Android's surfaceView
- testng - 如何在循环中多次运行具有许多测试方法的 testng 类文件
- c# - c# 后面的代码中绑定了不正确的数据
- logstash - Logstash 对 Crate DB 的支持