Reputation: 8637
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?
Upvotes: 1
Views: 991
Reputation: 2180
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
Upvotes: 4
Reputation: 16858
You could probably just serialise a List<ArrayList>
or even List<int[]>
, couldn't you?
Upvotes: 1