Array to JSon
by Prabakaran[ Edit ] 2012-01-07 17:23:16
function array1dToJson(a, p)
{
var i, s = '[';
for (i = 0; i < a.length; ++i)
{
if (typeof a[i] == 'string')
{
s += '"' + a[i] + '"';
}
else
{ // assume number type
s += a[i];
}
if (i < a.length - 1)
{
s += ',';
}
}
s += ']';
if (p)
{
return '{"' + p + '":' + s + '}';
}
return s;
}