Flutter how to convert String to List

后端 未结 1 1538
深忆病人
深忆病人 2021-01-02 17:38

I have this String.

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


        
相关标签:
1条回答
  • 2021-01-02 18:11

    Your string looks like a valid JSON, so this should work for you:

    import 'dart:convert';
    ...
    
    var a = '["one", "two", "three", "four"]';
    var ab = json.decode(a);
    print(ab[0]); // returns "one"
    
    0 讨论(0)
提交回复
热议问题