I am trying to dynamically pass a double array from C# to some JavaScript code. Here’s how I am doing it now:
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var jsLat = serializer.Serialize(lat);
I then call InvokeScript with jsLat as parameter.
When I try lat.length on the JS side, I get the correct length, but when I try to do lat[#] all the values come back as undefined.
Also, when I do alert(lat.valueOf()) I see all the values.
Why are all the values coming back as undefined?
You are looking for JSON.parse function on JavaScript side supported by all modern browsers. Unless you need to support IE7/IE6 it is built in function, for IE6/7 there are JavaScript implementations (check out http://json.org for details).
If you are using jQuery you can use jQuery.parseJSON that supports all browsers.