views:

118

answers:

3

What C-sharp type can I serialize to get JSON object with format "name":[[1,2,3],[1,2,3],[1,2,3]]

If serialize array like this public int[,] data = {{23,21,10},{45,43,50},{23,21,90}}; it gives format of "data":[23,21,10,45,43,50,23,21,90]

Or more generally, is there some list where i can find what type is serialized in which format?

A: 

Serialize an array of arrays?

Amber
A: 

You could probably just serialise a List<ArrayList> or even List<int[]>, couldn't you?

Phil.Wheeler
+2  A: 

As specified on MSDN,

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

As specified by Phil.Wheeler, this code does what you want:

List<int[]> name = new List<int[]>(){ new int[]{ 23, 21, 10 }, new int[]{ 45, 43, 50 }, new int[]{ 23, 21, 90 } }; 

string ser = (new System.Web.Script.Serialization.JavaScriptSerializer()).Serialize(name);

Hope it will help

mberube.Net
helped me out.. thanks.
rockinthesixstring