Multi-layer nested Json parsing

how to deal with multi-layer json, it is the most convenient to get the name? of faith mobile phone.

{
    "data":
    {
        "showStyle":"barscn",
        "areaList":
        [
            {
                "showModel":0,
                "showLen":5,
                "title":"",
                "lines":{
                    "style":{
                        "bgcolor":"ff0000",
                        "fgcolor":"ffffff", 
                        "fontsize":"36", 
                        "fontname":"simhei",
                        "alpha":1.0
                    },
                    "datas":
                    [
                        {   "style":"",
                            "cols":[
                                {"showName":"Nokia","currentShow":true,"style":""},
                                {"showName":"Apple","currentShow":true,"style":""}
                            ]
                        }
                    ]   
                }
            }    
        ]
    }
}

how to deal with it to make it universally applicable

Mar.13,2021

use recursion.


   var arr=[];
function run (v){
    if(v&&v.constructor==Array){
        v.forEach(value=>{
            run(value)
        })
        return
    }
    if(v&&v.constructor==Object){
        for(k in v){
            if(k=='showName'){
                arr.push(v[k])
            }
            run(v[k])
        }
    }
    
}
run(data)
console.log(arr)

JSON.parse ('{json data}') thus becomes object

Menu