flutter中的一个与Map相关的错误,每次我试图解析它时都会发生



我有一个包含两个标准键和值对的映射,如

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

正如你所看到的,里面还有一张名为receiver的地图。稍后使用for循环将值传递给接收器,并且添加的信息非常好。

for(int i=0; i<=n; i++)
{
_body['receiver'][i] = {
"receiver_name" : "abc",
};
}

我面临的问题是,当试图通过http.post将此映射发送到api调用时jsonEncode(body(已经被用来对映射进行编码以发送它。当发送那些简单的键值对时,我没有得到错误,但当我试图包括receiver字段时,我也得到了错误。

有人能告诉我这里需要什么吗?谢谢

如果没有以正确的方式进行,请尝试此

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

输出就像这个

{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}}

你现在可以对它进行编码

相关内容

  • 没有找到相关文章

最新更新