From:  "rush@manbert.com" <rush@manbert.com>
Date:  02 Mar 2007 01:31:03 Hong Kong Time
Newsgroup:  news.mozilla.org/netscape.public.mozilla.jseng
Subject:  

Re: Create an object tree in spidermonkey

NNTP-Posting-Host:  198.144.205.66

On Feb 13, 10:53 pm, Sune...@gmail.com wrote:
> Hi,
>
> I'm new to spidermonkey, and I would like some help on creating
> objects.
>
> I have data a structure as follows....
>
> interpretation: {
>      drink: "coke",
>      pizza: {
>           number: "3",
>           size: "large",
>            topping: "pepperoni"
>       }
>
> }
>
> I need to create a javascript object out of this structure.
> ie: I should be able to use interpretation.drink or
> interpretation.pizza.topping in a script....
>
> Could someone please help me with this...


To use the syntax you show, you would need to do this:
var interpretation = {   drink: "coke",
      pizza: {
           number: "3",
           size: "large",
            topping: "pepperoni"
       }
};

which is an object literal. If you had this in JSON format (a string
where the labels are quoted as well as the values) string called
myObjStr, then you can do this:

var interpretation = eval ( '(' + myObjStr + ')' );

Note that this is just JavaScript stuff. Nothing is specific to Spider
Monkey.

- Rush