gpt4 book ai didi

flutter - 当我在 Flutter 中打印 map 时,Flutter 中缺少双引号

转载 作者:行者123 更新时间:2023-12-05 08:35:54 29 4
gpt4 key购买 nike

我在 flutter 中有一个 map

Map<String, dynamic> map = {
'key1': 'Dog',
'key2': 'Chicken',
};
print(map);

实际结果

{
key1: Dog,
key2: Chicken
}

预期结果

{
"key1": "Dog",
"key2": "Chicken"
}

最佳答案

您可以使用以下任何一种方法。

Map<String, dynamic> map = {
'key1': 'Dog',
'key2': 'Chicken',
};

print(json.encode(map)); //approach - 1
print(JsonEncoder.withIndent(' ').convert(map)); //approach - 2

注意:不要忘记导入 dart:convert

关于flutter - 当我在 Flutter 中打印 map 时,Flutter 中缺少双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71204002/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com