tags:

views:

24

answers:

1

Hi all, i've a problem with json object (created from java Object1) that contains a List of Object2... i cannot access to the value of the object2 in the list og object1..

the json Object is

{
    "object": {
        "idItemGroup": "45",
        "path": "1",
        "dealer": "6",
        "refIdMacroItemGroup": "6",
        "description": "kb4",
        "price": "5.5",
        "qty": "1",
        "itms": {
            "@class": "list",
            "ecomm.datamodel.ItemModify": [
                {
                    "isDeleted": "false",
                    "isAdded": "false",
                    "idItem": "14",
                    "idLabel": "10029",
                    "label": "kb3",
                    "price": "5.5",
                    "dealer": "6",
                    "refItemGroup": "45"
                },
                {
                    "isDeleted": "false",
                    "isAdded": "false",
                    "idItem": "12",
                    "idLabel": "10025",
                    "label": "kc1",
                    "price": "5.5",
                    "dealer": "6",
                    "refItemGroup": "45"
                }
            ]
        }
    }
} 

but in js i can only get itms object? thanks in advance.

jsonObject.object.description (kb4 )

how i can get the value of idLabel in

A: 
labels = []
var items = jsonObject.object.itms["ecomm.datamodel.ItemModify"];
for(var i = 0; i < items.length; i++)
{
  labels.push(items[i].idLabel);
}

That is some really ugly JSON, particularly (but not only) the key with embedded periods.

Matthew Flaschen
Really thanks, i've found also another solution ( because it's no only javascript but there is a java class that use Xstream (com.thoughtworks.xstream.XStream) for serialize to json the object ...so the solution was xstream.alias("ITEMMODIFY", ecomm.datamodel.ItemModify.class);and then access to jsonObject.object.ITEMMODIFY.properties :)also really thanks!
Vito