I have a list. I want to convert it to string. However, the results are a bit different from what I expected.
Expected result:
'["a", "b", "c", "d"]'
Actual result:
[a, b, c, d]
My code:
final List list = ["a", "b", "c", "d"];
print(list.toString());
How can I get my expected results? I would appreciate any help. Thank you in advance!
CodePudding user response:
You could use the jsonEncode
of it to get the desired result:
print(jsonEncode(list));
CodePudding user response:
You can try jsonEncode
:
final List list = ["a", "b", "c", "d"];
print(jsonEncode(list));
Output:
["a","b","c","d"]
CodePudding user response:
You can simply do this by using json.encode()
function:
final list = ['a', 'b', 'c', 'd'];
final result = json.encode(list);