var a = [{'answers' : [{'text':'Cloud','score':10},],},];
main()
{
print(a[0]['answers']);
}
我想在'score'中打印数字10谁来帮我修复代码!!首先感谢!!
你的问题是正确的null-safety,它抱怨使用['answers']
的值。原因是Map
上的[]
操作符返回一个可空类型,因为如果该元素不存在于Map
中,结果可以是null
。
我在下面使用!
向编译器保证,您确信该元素确实存在于Map
中,因此它停止抱怨。但是,如果返回值是null
:
var a = [
{
'answers': [
{'text': 'Cloud', 'score': 10},
],
},
];
void main() {
print(a[0]['answers']![0]['score']); // 10
}