This example shows it very simply:
var a = [];
a.push({ name: 'x1' });
a.push({ name: 'x2' });
console.log(JSON.stringify(a));
In the console log you get:
[{"name":"x1"},{"name":"x2"}]
from a comment on this page:
http://freshbrewedcode.com/jimcowart/2013/01/29/what-you-might-not-know-about-json-stringify/
So testing this:
var start = 21;
var a = [];
a.push({ name: start });
a.push({ name: 'x2' });
console.log(JSON.stringify(a));
In the console log you get:
[{"name":21},{"name":"x2"}]
GOOD!!!!
VERY STRANGELY, EVEN WHEN I SEND IT AS JSON, THE SCRIPT I HAVE WRITTEN DOESN'T SEEM TO LIKE IT.
I DON'T KNOW QUITE WHY!
Surprisingly, a variation on push seems to work:
var start = 21;
var end = 193;
var color = "blue";
var a =[];
a.push({ 'start': start, 'end': end, 'color': color });
This gives data that the molecule renderer seems to like.
No comments:
Post a Comment