将多维数组序列化和反序列化为JSON

将多维数组序列化和反序列化为JSON

问题描述:

我正在使用内置库JavaScriptSerializer对多维数组进行序列化和反序列化.

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

MSDN中指出A multidimensional array is serialized as a one-dimensional array, and you should use it as a flat array.

我试图反序列化它,但一直得到Unable to cast object of type 'System.Double[]' to type 'System.Double[,,]'.

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.

如果其将多维数组序列化为平面数组,那么您将无法将其反序列化回多维数组.

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

看看这个线程,其中一种解决方案使用Json.net对多维数组进行序列化和反序列化.

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

如何对包含多维数组的json对象进行反序列化? /a>

How to deseralize json object that contains multidimensional array?