0

I have following JSON:

{
"category": {
    "category_identification": "1",
    "category_name": "C1",
    "image_one": "1.PNG",
    "image_two": "1_.PNG",
    "logo": "LOGO_1.PNG",
    "category_description": "DESCRIPTION"
},
"responseCode": "1"
}

I have to check if responseCode is 1 then have to display information from category (category_description, logo, etc.). I tried following code:

              $.each(data1, function(key, value) {
                    if (data1.responseCode == '1') {
                        alert(value.category_name)  
                    }
                });

where data1 is a JSON. I am getting undefined result.

1 Answers1

0

Maybe just change value to data1.category? Like this:

$.each(data1, function(key, value) {
    if (data1.responseCode == '1') {
        alert(data1.category.category_name)  
    }
});

I wrote this answer because I don't see an array of JSONs, but only one JSON object. If that's the case, we can make it even simpler:

if (data1.responseCode == '1') {
    alert(data1.category.category_name)  
}
Nomce
  • 738
  • 1
  • 6
  • 18