0

I am reciving JSON data in this format .

[
    {
        "id": "0004",
        "name": "Thums Up",
        "image": {
            "url": "pepsicup.jpg",
            "width": 200,
            "height": 200
        },
        "category": [
            {
                "category_name": "can",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "250ml"
                    },
                    {
                        "type": "300ml"
                    },
                    {
                        "type": "330ml"
                    }
                ]
            },
            {
                "category_name": "bottle",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "350ml"
                    },
                    {
                        "type": "600ml"
                    }
                ]
            },
            {
                "category_name": "fountain",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "small"
                    },
                    {
                        "type": "large"
                    }
                ]
            }
        ]
    },
    {
        "id": "0005",
        "name": "Pepsi",
        "image": {
            "url": "images/0001.jpg",
            "width": 200,
            "height": 200
        },
        "category": [
            {
                "category_name": "can",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "250ml"
                    },
                    {
                        "type": "300ml"
                    },
                    {
                        "type": "330ml"
                    }
                ]
            },
            {
                "category_name": "bottle",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "350ml"
                    },
                    {
                        "type": "600ml"
                    }
                ]
            },
            {
                "category_name": "fountain",
                "image": "images/0001.jpg",
                "type": [
                    {
                        "type": "small"
                    },
                    {
                        "type": "large"
                    }
                ]
            }
        ]
    }
]

If once the name is matched to Thums Up , is it possible to retrieve the category_name

can , bottle and fountain in my case ??

I have tried below , but could't able to continue once the name is matched ??

Could you please help me retriving the category_name for Thumps Up .

var result = JSON.stringify(retdata);



for(var i=0;i<result.length;i++)
        {
            if(i.name="Thums Up")
            {

            }
        }
user3674364
  • 69
  • 1
  • 8

1 Answers1

1

you have array and then in array item there is another array, you need to do like this:

$.each(retdata,function(index,item){

$.each(item,function(index1,item1){

    console.log(item1);
});
    console.log(item);

});

FIDDLE DEMO

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160