As mentioned in another reply, "theObject" is an object.
So, building a string with
"(" + theObject + ")";
will not give you what you'd expect. If that were to work at all you'd
likely end up with a string of "([Object])" - not what you want.
If you really must do the eval(), then it should be something like
var json = eval( '{ "key" : "value" }' );
But, eval() is evil and should be avoided wherever possible. Mostly
because it is mis-used, introduces various issues, and is known to be an
expensive call in terms of processing speeds. It *is* the right tool in
some cases though...
In your code, I'd recommend doing as MorningZ mentioned:
var theObject = { "key": "value"};
alert(theObject.key);
HTH
Shawn
theozmanbo wrote:
Why won't this work??? Nothing pops up for the alert.
<script type="text/javascript">
var theObject = {"key": "value"};
var JSON = eval ("("+theObject+")");
alert(JSON.key);
</script>