Array to JSon

by Prabakaran 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;
}

Tagged in:

1006
like
0
dislike
0
mail
flag

You must LOGIN to add comments