My value from json : "[[2.1,2.2],[1.0,2.5]]". How to convert this string to List<List> ?
CodePudding user response:
You start off with a List<dynamic>
so you can just cast each of its elements to List<double>
.
void main() {
final decoded = json.decode('[[2.1,2.2],[1.0,2.5]]') as List<dynamic>;
final listDoubleDouble =
decoded.map<List<double>>((e) => e.cast<double>()).toList();
print(listDoubleDouble.runtimeType);
}
CodePudding user response:
String myJSON = '[[2.1,2.2],[1.0,2.5]]';
var json = jsonDecode(myJSON);
print(json[0][0]);