3

I am using the built-in library JavaScriptSerializer to serialize and deserialize a multidimensional array.

It is stated in the MSDN that A multidimensional array is serialized as a one-dimensional array, and you should use it as a flat array.

I have tried to deserialize it, but kept getting Unable to cast object of type 'System.Double[]' to type 'System.Double[,,]'.

double[, ,] y = serializer.Deserialize<double[, ,]>(jsonMatrix);

Does this mean that i have re-construct it back manually ? If so, any solutions.

ykh
  • 1,775
  • 3
  • 31
  • 57
  • Does this answer your question? [How do I convert a c# two-dimensional array to a JSON object?](https://stackoverflow.com/questions/1291076/how-do-i-convert-a-c-sharp-two-dimensional-array-to-a-json-object) – ruffin Sep 17 '21 at 18:06

1 Answers1

1

If its serializes multi dimension array into flat array then you won't be able to de-serialize it back into multi dimension array.

Have a look at this thread, one of the solution uses Json.net to serialize and de-serialize multi dimension array.

How to deseralize json object that contains multidimensional array?

Community
  • 1
  • 1