flutter - 为什么我收到 Flutter HTTP 包错误类型“字符串”不是“地图”类型的子类型'?
问题描述
我正在使用 Flutter 的 HTTP 包的确切代码示例,但正文内容不同,如下所示:
res = await http.post(
Uri.parse("http://localhost:3000/login"),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'email': "test@test.com",
"password": "testPassword",
}),
);
然而,我收到了type 'String' is not a subtype of type 'Map<String, dynamic>'
正文格式的错误。而且我不能在没有编码的情况下离开身体,Map<String, String>
因为这会使 API 失败。
我应该怎么办?
解决方案
jsonEncode 输出一个字符串。您只需将地图发送到您的 API。
推荐阅读
- java - 突然出现 NoSuchFieldError: usingExperimentalRuntime in App Engine with GCE library
- javascript - TypeError:未定义不是对象(评估“this.state.videos.map”)
- shell - Ubuntu 20.04 获取 shell 非常慢
- python - .type() 方法与 Python 中的 type() 函数
- spring-boot - Spring Boot:带有 404 状态码的 Whitelabel 错误页面
- asp.net-mvc - 如何在 mvc 中使用引导 Glyphicons
- sql - Teradata 使用 XMLAGG 连接多行在 XmlAgg 函数中出现问题或任何等效逻辑连接多行
- powerbi - 电源 BI。在 MAXX 中使用 SUMMARIZE 函数
- angular - 将带有字符串日期的json响应转换为JS日期的Angular 8方法?
- laravel - 如何使用 Laravel 从 Chart.js 上的数据库中获取数据?