简体   繁体   English

将 object 转换为可编码的 object 失败:_linkedhashmap len:1 Flutter

[英]Converting object to an encodable object failed: _linkedhashmap len:1 Flutter

I have a map which contains two standard key and value pairs like我有一个 map 包含两个标准键和值对,例如

_body = {
          "expected_time": "$Time",
          "payment": "$payment",
          "receiver" : {},
};

And another map named receiver inside it as you can see.如您所见,其中还有另一个名为接收器的 map。 Values are being passed to the receiver later using a for loop and the information is being added just fine.稍后将使用 for 循环将值传递给接收器,并且可以很好地添加信息。

for(int i=0; i<=n; i++)
{
  _body['receiver'][i] = {

            "receiver_name" : "abc",
};
}

The issue I'm facing is when trying to send this map to an api call via http.post there jsonEncode(body) has been used to encode the map to send it. The issue I'm facing is when trying to send this map to an api call via http.post there jsonEncode(body) has been used to encode the map to send it. When sending those simple key value pairs I'm getting no error but when I'm trying to include the receiver field as well I'm getting the error "Converting object to an encodable object failed: _linkedhashmap len:1".发送这些简单的键值对时,我没有收到任何错误,但是当我尝试包含接收器字段时,我收到错误“将 object 转换为可编码的 object 失败:_linkedhashmap len:1”。

Can anyone please tell me what I need to here?谁能告诉我我需要在这里做什么? Thanks!谢谢!

you are not making it in the right way, try this你没有以正确的方式做到这一点,试试这个

var _body = {
 "expected_time": "time",
 "payment": "payment",
 "receiver" : {},
};

for(int i=0; i<=3; i++) {
 _body.addAll({
  'receiver[$i]': {
    "receiver_name": "abc",
  }
 });
}
print(_body);

and the output is like this output 是这样的

{expected_time: time, payment: payment, receiver: {}, receiver[0]: {receiver_name: abc}, receiver[1]: {receiver_name: abc}, receiver[2]: {receiver_name: abc}, receiver[3]: {receiver_name: abc}}

you can now encode it您现在可以对其进行编码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在api调用上将对象转换为可编码对象失败:_LinkedHashMap len:2 - Converting object to an encodable object failed on api call: _LinkedHashMap len:2 未处理的异常:将 object 转换为可编码的 object 失败:_LinkedHashMap - Unhandled Exception: Converting object to an encodable object failed: _LinkedHashMap DioError [DioErrorType.other]:将 object 转换为可编码的 object 失败:_LinkedHashSet len:1 Flutter - DioError [DioErrorType.other]: Converting object to an encodable object failed: _LinkedHashSet len:1 Flutter 在 Flutter 中将对象转换为可编码对象失败 - Converting object to an encodable object failed in Flutter Flutter:未处理的异常:将对象转换为可编码对象失败:“AddProjectModel”的实例 - Flutter: Unhandled Exception: Converting object to an encodable object failed: Instance of 'AddProjectModel' 将 object 转换为可编码的 object 失败:“_File”实例 Flutter - Converting object to an encodable object failed: Instance of '_File' Flutter 由于 404,将 object 转换为可编码 object 失败 - Converting object to an encodable object failed due to 404 在 http 调用中将 object 转换为可编码的 object 失败 - Converting object to an encodable object failed in http call 将 object 转换为可编码的 object 失败:“偏移”实例 - Converting object to an encodable object failed: Instance of 'Offset' 将 object 转换为可编码的 object 失败:“LeadSource”实例 - Converting object to an encodable object failed: Instance of 'LeadSource'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM