0

I have got this as response

[
    {
        "name": "Large, 100 Ml",
        "image": "http://hostip:8080/OrderSnacks/JSON_images/icecream_cup_vanilla.jpg",
        "quantity": "1",
        "price": "75",
        "toppings": []
    },
    {
        "name": "Regular, 50 Ml",
        "image": "http://hostip:8080/OrderSnacks/JSON_images/icecream_cup_vanilla.jpg",
        "quantity": "2",
        "price": "150",
        "toppings": [
            {
                "name": "Regular, 50 Ml0",
                "value": [
                    "Honey with Chocolate Sauce  10 ML"
                ]
            },
            {
                "name": "Regular, 50 Ml1",
                "value": [
                    "Honey with Chocolate Sauce  10 ML",
                    "Honey with Carmel  10 ML"
                ]
            }
        ]
    }
]

How can i read the toppings array values ??

I tried to read this way

for (var n = 0; n < toppins.values.length; n++) 
{
alert(toppins.values[n]);
}

But it is giving errror can't read property of undefined

could anybody please help me on this .

2
  • 3
    Is it toppins or toppings? Also, there are two layers above it. Commented Jun 20, 2014 at 15:54
  • toppings is an array. It doesn't have a value property, its elements do. Commented Jun 20, 2014 at 16:13

2 Answers 2

1

Demo Fiddle

Javascript code:

for (var i = 0; i < json.length; i++) {
    var obj = json[i].toppings;
    for (var j = 0; j < obj.length; j++) {
        alert(obj[j].value);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You have a typo, it's value not values and toppings not toppins - per your JSON:

for (var n = 0; n < toppings.value.length; n++) 
{
alert(toppings.value[n]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.