Trying to convert a two dimensional array to a two dimensional JSON.Net array.
Is there something wrong with the code below? Or just isn’t this supported by JSON.Net?
var A = new int[2, 4] { { 1, 1, 1, 1 }, { 2, 2, 2, 2 } };
Console.WriteLine(JsonConvert.SerializeObject(A));
// CONSOLE: [1,1,1,1,2,2,2,2]
//
// NB. displays a one dimensional array
// instead of two e.g. [[1,1,1,1],[2,2,2,2]]
Javascript doesn’t have the notion of a 2D array in the same sense that C# does. In order to get an array like that described here, you’ll need to create an array of arrays instead.
Update:
It sounds like JSON.NET now converts multidimensional arrays into an array of arrays in JSON, so the code in the OP will work the same as if you used the code above.