I serialized a javascript array using JSON.stringify and got a string which I used it 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?
The 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 whether you wanted a list of arrays or a straight up list of each number.. so I gave both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With