颤振如何将String转换为List< String> [英] Flutter how to convert String to List<String>

查看:66
本文介绍了颤振如何将String转换为List< String>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个 String

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

我想将其转换为 List<字符串>
问题是它也会返回方括号。我要列出看起来是这个 [一个,两个,三个,四个] 不是 [[,两个,三个,四个]]
如何正确转换?

I want to convert this to List<String>. The problem is it returns square bracket too. I want to List looks this ["one", "two", "three", "four"] not [["one", "two", "three", "four"]]. How can I convert this properly?

推荐答案

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

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"

这篇关于颤振如何将String转换为List&lt; String&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆