Post 对象中的 Flutter Bool 数据

标签 flutter dart

我有一个帖子对象。就像下面一样。

{
       "facilities": value.join(","),
       "start_date": startDate.toString().substring(0, 10),
       "end_date": endDate.toString().substring(0, 10),
       "over_ratio": false,
       "total": true
}

我在正文中发送此对象,但服务器向我发送 404 消息。但是当我编写像 "over_ratio": "false", "total": "true" 这样的 bool 数据时,服务器会理解这个 bool 数据错了。

var response = await http.post(url, body: body);
    if (response.statusCode == 200) {
     print(response.body);
    }

我需要发送此正文 bool 数据,例如:

{
       "facilities": value.join(","),
       "start_date": startDate.toString().substring(0, 10),
       "end_date": endDate.toString().substring(0, 10),
       "over_ratio": false,
       "total": true
}

我也尝试过,但出现同样的问题:

json.encode({
       "facilities": value.join(","),
       "start_date": startDate.toString().substring(0, 10),
       "end_date": endDate.toString().substring(0, 10),
       "over_ratio": false,
       "total": true
});

如何正确发送此帖子? 谢谢。

最佳答案

您是否尝试过使用jsonEncode(body)发布数据

希望它能发挥作用。

关于Post 对象中的 Flutter Bool 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65953268/

相关文章:

flutter - 如何将 InternalLinkedHashMap 转换为 Map<dynamic, dynamic>?

firebase - 如何消除实时数据库Firebase抖动中的自动生成的 key

flutter - 在 channel plugins.flutter.io/image_picke 上找不到方法 pickImage 的实现

dart - 当我从页面 B 返回时,如何刷新页面 A 上的小部件?

flutter - 无法构建 flutter 工具

json - 使用云函数时,来自 firestore 的时间戳被转换为 Map

android-studio - 在 Debug模式下运行的应用程序仅适用于 Flutter

flutter - 波动-实际值和显示值之间的差异

dart - TextSize 不会根据 deviceSize 或 devicePixelRatio 进行缩放

dart - Flutter 中的日期时间格式 dd/MM/YYYY hh :mm