将多维数组序列化和反序列化为JSON [英] Serialize and Deserialize Multidimensional Array to 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.
How to deseralize json object that contains multidimensional array?
这篇关于将多维数组序列化和反序列化为JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!