-4

I need to parse this JSON in list structure like setup->Finantial Setup->Banks ->charge Item

[
    {
        "label_name": "Setup",
        "data": {
            "name": "Setup",
            "url": "/setup",
            "sub_menues": [
                {
                    "       ": {
                        "name": "Finantial Setup",
                        "url": "Setup/Finantial Setup",
                        "sub_menues": [
                            {
                                "sub_list": {
                                    "name": "Banks",
                                    "url": "/setup/Finantial Setup/Banks"
                                }
                            },
                            {
                                "sub_list": {
                                    "name": "Charge Items",
                                    "url": "/setup/Finantial Setup/Charge Items"
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
]
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

0

Here is some code that finds all the sub_list items with the name 'Charge Items'. We really don't know what you want in your question but I hope this helps.

var json = [{"label_name": "Setup", "data": {"name": "Setup", "url": "/setup", "sub_menues":
                            [{" ": {"name": "Finantial Setup", "url": "Setup/Finantial Setup",
                                        "sub_menues": [{"sub_list": {"name": "Banks", "url": "/setup/Finantial Setup/Banks"}}, 
                                            {"sub_list": {"name": "Charge Items", "url": "/setup/Finantial Setup/Charge Items"}}]}}]}}];

var sm = json[0].data.sub_menues;
        var urls = [];
        for (var i = 0; i < sm.length; i++) {
            var aSm = sm[i] //get a sub menu
            var aSmObject = aSm[" "]; //this is a little sketchy
            var sm2 = aSmObject.sub_menues;
            for (var j = 0; j < sm2.length; j++) {
                var subList = sm2[j].sub_list;
                if(subList.name.toLowerCase() === "charge items"){
                    urls.push(subList.url);
                }
            }
        }
        console.log(urls);
        alert(urls);