ASP.NET JavascriptSerializer for Array


I need to throw some database entry which are as simple as TIME, for this I got a string array in my ASP.NET code behind. I was throwing this String Array in JSON format after using JavascriptSerialize.Serialize method and it is making not so perfect Json script. I said it is not making perfect json because the expect result for me was something like this:

[“10:20″,”10:30″,”10:40”]

but it was returing something like

{“d”:”[\”10:20\”,\”10:30\”,\”10:40\”]”}

the difference is that it is converting the array in to string, however the ideal result can be

{“d”:[“10:20″,”10:30″,”10:40”]}

But we cannot change that functionality now, so what I realise we should use the eval function of javascript to make our Jquery or whatever JSON parse you are using. So my Jquery code looks like

….

success: function(data) {
var items = [];
$.each(data, function(ind, val) {
var myobject = eval(val);
$.each(myobject, function(i, v) {                   
items.push(‘<option value=”‘ + v + ‘”>’ + v+ ‘</option>’);
});
});
}

this convert the String to Javascript object using Eval function. Easy enough !!!

, , , , ,