输入'_InternalLinkedHashMap '不是类型转换中'String'类型的子类型

问题描述 投票:0回答:1

我试图将嵌套的JSON对象发布到API。这是我正在尝试的简单代码。

Map m = {
   "email": '[email protected]',
   "password": "123",
   "billing" : {
      "first_name": "Samarth",
      "last_name": "Agarwal",
   }
};

final response = await http.post(url, body: m, headers: {
   "Content-Type": "application/json",
   "Accept": "application/json"
});

我收到错误消息:type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'String' in type cast。如果我没有传入billing对象,这是另一个映射本身,那么请求成功完成。

如何使用dart中的HTTP成功将嵌套的JSON对象发送到API?

json http post dart flutter
1个回答
0
投票

你需要用json.encode(m)对它进行json编码,然后将其作为正文发送。

© www.soinside.com 2019 - 2024. All rights reserved.