I want to send a C# 2 dimenssions string array to my JS client page.
server:
string[,] info = ib.GetInfo();
//info is [["string1","string2","string3"],["string4","string5","string6"]]
JavaScriptSerializer ser = new JavaScriptSerializer();
return this.Content((new JavaScriptSerializer()).Serialize(info), "text/javascript");
ON the client JS side:
var mysr= JSON.parse(resp );
"string1","string2","string3","string4","string5","string6"
The result mysr is a 1 dimenssion array!
What is wrong? any help would be appreciated. The string can also contain quotes and double quotes
JSON.parseshould be able to handle a 2-dimensional array without issue. I believe the problem lies inJavaScriptSerializerconverting it to a 1-dimensional array.id.GetInfo();returnsstring[,]and notstring[][]. You'd most likely get an exception if this weren't the case, but just as a sanity check... Also, try to create a nested loop to convertstring[,]intostring[][]and try to serialise that, just to see what happens...