2

String data= '[1, 2, 3]';

i want to convert my string to List<int>

expectations: [1, 2, 3]

what i got using my code:

print(json.decode(data));

result: 1

dataType: int

2
  • 1
    try this List<int>.from(json.decode(data).map((x) => x)); Commented May 12, 2020 at 12:20
  • The given code gives your expected value already. Commented May 13, 2020 at 9:44

1 Answer 1

3

You can do this,

import 'dart:convert';

var list = json.decode(data);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.