I want to convert a string to multi-level list, but I cannot find a efficient way to do.
From String: [[1,2,3],[1,2]]
To List: List< List < int>>
I want to convert a string to multi-level list, but I cannot find a efficient way to do.
From String: [[1,2,3],[1,2]]
To List: List< List < int>>
String str = '[[1,2,3],[1,2]]';
List<List<int>> list=[];
for(String s in str.split('],[')){
List<int> l = [];
String formattedString = s.replaceAll('[','').replaceAll(']','');
for(String innerS in formattedString.split(',')){
l.add(int.parse(innerS));
print(l);
}
list.add(l);
}
Output: [[1, 2, 3], [1, 2]]