Parse JSON Array without key using Dart

I can't seems to find a solution to parse a json array without key using Dart language. All i can find is by using Java. I need to parse something like this..

[
 5,
 10,
 15,
 20
]

Java solution is from here

Please inform me if I have duplicate question. Thank you!

Upvotes: 1

Views: 2097

Answers (2)

Ryan Z
Ryan Z

Reputation: 70

import 'dart:convert';
void main() {
  var x = "[ 5, \n 10, \n15\n, 20]";
  var b = jsonDecode(x);
  print(b[3]); //prints 20

}

Upvotes: 0

Richard Heap
Richard Heap

Reputation: 51751

Just use json.decode as normal, for example:

List<dynamic> l = json.decode('[5, 10, 15, 20]');

It happens that the members of l will all be ints

Upvotes: 3

Related Questions