How to split a string of an array of integers in List <int []>?

I serialized a javascript array using JSON.stringify and got a string that I used as:

string test = "[[0,0],[0,0],[0,0],[0,0],[0,0],[0,0]]"; 

How do I convert 'test' to a C # List variable?

+6
source share
1 answer

Basic JavaScriptSerializer works for this:

 using System.Web.Script.Serialization; string test = "[[0,2],[0,0],[0,0],[0,0],[0,0],[0,0]]"; var listOfInts = new JavaScriptSerializer() .Deserialize<int[][]>(test) .SelectMany(x => x).ToList(); var listOfArrays = new JavaScriptSerializer() .Deserialize<int[][]>(test) .Select(x => x).ToList(); 

Not sure if you need a list of arrays or a direct list of each number. So I gave both.

+2
source

Source: https://habr.com/ru/post/955639/


All Articles