1

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?

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

Serialize an array of arrays?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.