android - 如何在颤振中创建 JSON 对象?
问题描述
我正在开发一个应用程序,我想在其中填写注册表并将这些数据传递给 API。我尝试了几乎所有的解决方案,但没有解决这个问题。
填写表格后我得到了这种类型的数据
[
{Date of Birth of the Baby: 08/01/1997},
{Gender of the baby: male},
{Time of Birth of the Baby: 12.00 pm},
{Father's Name: Nnn},
{Mother's Name: Hbhh},
{Any Extra Details?: Bnn}
]
我想要这种类型的数据
{
"Date of Birth of the Baby": "08/01/1997",
"Gender of the baby": "male",
"Time of Birth of the Baby": "12.00 pm",
"Father's Name": "Nnn",
"Mother's Name": "Hbhh",
"Any Extra Details?": "Bnn"
}
var 字段数据 = []; 最终 myControllers = [];
mydynamicData() {
for (var i = 0; i <= widget.fieldData.length; i++) {
fieldsData.add({
widget.fieldData[i]['question'],
myControllers[i].text != null || myControllers[i].text != ""
? myControllers[i].text
: ""
});
}
print("fieldsData:${fieldsData}");
}
这是我的方法,我知道这个问题是由于 for 循环而发生的,但是没有 for 循环我没有得到所有字段数据。所以请帮忙。
解决方案
进口:
import 'dart:convert';
那么你可以使用:
json.encode(fieldsData);
由于您有一个对象列表,因此可能需要在列表中为每个项目调用 json.encode ,然后对结果进行编码。
推荐阅读
- oracle-apex - 如何在 Oracle Apex 中实现悲观锁定
- plotly - 情节问题
- haskell - foldMap 连体
- amazon-web-services - 如何使用 Python-AWS lambda 中的返回对象?
- flutter - 是否可以在颤动中使用 FFMPEG 将 2 个视频合并为一个视频
- shopify - 使用 Shopify API 计算总销售额
- c# - 如何修复我的冲刺在跳跃时无法正常工作以及如何添加冷却时间?
- vba - 使用 .oft 模板回复并显示图片和附件
- bash - 如何列出和排序名称中只有一个数字的图片?
- spring - SpringBootTest Spring Security InMemoryClientRegistrationRepository NoSuchBeanDefinitionException 在测试