Your JSON is invalid; arrays cannot have strings as keys. It needs to look like:
{
"product": {
"Clothing": {
"Shirt": "$4.99"
},
"Food": {},
"Electronics": {}
}
}
Or may be like this:
{
"product": [
{
"category": "Clothing",
"items": [{
"name": "Shirt",
"price": "$4.99"
}]
}, {
"category": "Food",
"items": []
}, {
"category": "Electronics",
"items": []
}
]
}
To iterate over this data, use $.each
a couple of levels deep:
$.each(cwData.product, function (i, product) {
console.log(product.category + " (" + product.items.length + " items)");
$.each(product.items, function (i, item) {
console.log("\t" + item.name + ": " + item.price);
});
});
// output:
//
// Clothing (1 items)
// Shirt: $4.99
// Food (0 items)
// Electronics (0 items)