一尘不染

Flutter如何将String转换为List

flutter

我有这个String

  var String a = '["one", "two", "three", "four"]';
  var ab = (a.split(','));
  print(ab[0]); // return ["one"

我想将其转换为List<String>。问题是它也返回方括号。我要列出看起来["one", "two", "three", "four"]不是这样[["one", "two", "three", "four"]]。如何正确转换?


阅读 3570

收藏
2020-08-13

共1个答案

一尘不染

您的字符串看起来像有效的JSON,因此它应该对您有用:

import 'dart:convert';
...

var String a = '["one", "two", "three", "four"]';
var ab = json.decode(a);
print(ab[0]); // return ["one"
2020-08-13