http - 在类型转换中出现错误 "type ' List<Map<String, Object>>' is not a subtype of type ' String'

标签 http dictionary post dart

运行以下代码时出现错误:

http.post(url,
body: {"access_token": "bfa67f6f8389f421d8ac0106f040d19b40d8a69112402a76b87d66aea86a",
  "title": "HelloWorld!",
  "content": [{
    "tag": "p",
      "children": 
        ["Hello world!"]
      }
    ],
  "return_content": true
},

我知道 dart 在提示,因为我有一个 array which contains a map within my map . 我该如何处理?

编辑: 我通常会将其编码为 JSON,但 API只接受字符串

最佳答案

body 参数的类型必须是 String,但事实并非如此。 您的值看起来像一个类似 JSON 的结构,因此您可能希望使用 json 编码器将该对象结构编码为 String:

import "dart:convert";
...
var body = jsonEncode({"access_token": "..... " ... });
http.post(url, body: body);

关于http - 在类型转换中出现错误 "type ' List<Map<String, Object>>' is not a subtype of type ' String',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51896468/

相关文章:

php - 有没有办法缩短 PHP 的 HTTP 响应?

html - 编写嵌入式 Web 服务器时如何正确构建 favicon.ico 响应

python - 我怎样才能将json文件制作成字典?

python - 在 json 中搜索键,如果该数组中不存在键,则添加默认值

flutter - Dart - 从 map 中的 map 读取键和值

objective-c - 使用 JSON-Framework 准备一个 json 对象以通过 HTTP 请求 Objective-C 发布

ios - ASIFormDataRequest POST 请求问题

php - 使用 post 和 JWS 发送 JSON 数据

python - 如果页面不需要 Javascript,是什么阻止了它?

post - 在某些机器上使用 SSL 的 ActiveX 控件不会 POST 到 IE9 中的 URL