我想把字符串转换成2d数组在 dart 扑
[[Service, 300, 1], [Service, 4200, 1]]
这是一个字符串,我想把它转换成一个列表,这样我就可以在Flutter中使用下面的ListView。
List<String> stringList = (jsonDecode(serviceWantList) as List<dynamic>).cast<String>();
我试过了,但我没有得到我想要的结果。
我想访问这样的列表
[[Service, 300, 1], [Service, 4200, 1]]
我想在2列表中转换它,所以我访问像index[0][0]
,index[0][1]
等。
1条答案
按热度按时间aemubtdh1#
jsonDecode将不起作用,因为字符串不是有效的JSON。尝试执行以下操作:
问题是字符串包含未加引号的文本,这在JSON中是不允许的;因此,我们需要将字符串中的所有非数字值括在双引号(“)中。