If I create a JavaScript object like:
var lst = [];
var row = [];
row.Col1 = \'val1\';
row.Col2 = \'val2\';
lst.push(row);
And then convert it
Since an array is a datatype in JSON, actual instances of Array
are stringified differently than other object types.
If a JavaScript Array
instance got stringified with its non-numeric keys intact, it couldn't be represented by the [ ... ]
JSON array syntax.
For instance, [ "Col1": "val1"]
would be invalid, because JSON arrays can't have explicit keys.
{"Col1": "val1"}
would be valid - but it's not an array.
And you certainly can't mix'n'match and get { "Col1": "val1", 1, 2, 3 ]
or something.
By the way, this works fine:
var lst = [];
var row = {};
row.Col1 = 'val1';
row.Col2 = 'val2';
lst.push(row);
alert(JSON.stringify(lst));