Serialize and Deserialize Multidimensional Array to JSON

佐手、 提交于 2019-12-11 05:02:02

问题


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.


回答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?



来源:https://stackoverflow.com/questions/37316910/serialize-and-deserialize-multidimensional-array-to-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!