Andrew Poulos wrote:
There's an object:
foo = new Object();
and a property called 'bar' with a value of 1 is to be added to it using
JSON. If I try the following it only demonstrates my ignorance:
var str = "{foo:{bar:1}}";
eval(str);
alert(foo.bar) // gives undefined
What you are trying to do is the equivalent of initialising a variable
with an object literal:
var foo = {bar : 1};
Presuming you are using AJAX or similar to return JSONtext, then
depending on how you want do it, you can do:
var JSONtext = '{bar:1}';
var foo = eval( '(' + JSONtext + ')' );
or
eval( 'var foo = ' + JSONtext );
Maybe you want to do:
var JSONtext = 'var foo = {bar:1}';
eval(JSONtext);
Over to you...
--
Rob