0

I have simply list in my flutter app:

 var items = List<String>();
 items.add('1');
 items.add('2');
 items.add('3');

I converted it to string:

 var values =items.join(',');

Result:

 "[1,2,3]"

But I need json array, like it:

 ["1","2","3"]

How I create it from my list? it should be easy - but I'm stuck. any advice?

1 Answer 1

2
 import 'dart:convert';

 var items = List<String>();
 items.add('1');
 items.add('2');
 items.add('3');
 // or even better: var items = ['1','2','3'];

 print(json.encode(items));

output:

["1","2","3"]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.