如何获取JS中的“屋顶隔热”阵列值?甚至可以使用重复的属性名称吗?
我尝试了productListing ['Roofing Insulation'] ['Roofing Insulation']和许多其他类型的语法,但均未成功。我知道重复的做法不好,但这就是我要做的所有事情...
{
"storeServices":{
"Local Services":[
"Rooftop",
"EPDM",
"Next-Day Delivery Available"
],
"National Services":[
"Covered",
"Window",
"Job Site Signs"
]
},
"productListing":{
"Roofing Insulation":{
"Roofing Insulation":[
"Celotex",
"Dow",
"Foamular",
"Johns Manville",
"Pactiv",
"Tyvek"
]
},
"Other Products":{
"Other Products":[
"Caulks/Sealants",
"Shutters",
"Tools & Equipment",
"Engineered Lumber",
"Roofing & Siding Accessories"
]
},
"Low Slope Roofing":{
"Low Slope Roofing":[
"Johns Manville",
"Mule-Hide Products",
"Versico"
]
},
"Steep Slope Roofing":{
"Concrete & Clay Roof Tiles":[
"Vande Hey Raleigh"
],
"Asphalt Shingles":[
"CertainTeed",
"GAF",
"Owens Corning"
]
},
"Windows & Doors":{
"Replacement Windows":[
"Pella"
],
"New Construction Windows":[
"Pella"
],
"Exterior Doors":[
"Pella"
],
"Skylights":[
"Velux"
]
},
"Siding":{
"Vinyl Siding":[
"Mastic Home Exteriors"
]
}
},
"branchDetails":{
"branchNumber":"1"
}
}
答案 0 :(得分:0)
除非我们看到您尝试过的内容和您的代码,否则我们将无济于事。 如果您按如下方式访问它,它应该可以工作:
obj.productListing['Roofing Insulation']['Roofing Insulation']
下面是一个向您展示此内容的示例:
var obj = {
"storeServices": {
"Local Services": [
"Rooftop",
"EPDM",
"Next-Day Delivery Available"
],
"National Services": [
"Covered",
"Window",
"Job Site Signs"
]
},
"productListing": {
"Roofing Insulation": {
"Roofing Insulation": [
"Celotex",
"Dow",
"Foamular",
"Johns Manville",
"Pactiv",
"Tyvek"
]
},
"Other Products": {
"Other Products": [
"Caulks/Sealants",
"Shutters",
"Tools & Equipment",
"Engineered Lumber",
"Roofing & Siding Accessories"
]
},
"Low Slope Roofing": {
"Low Slope Roofing": [
"Johns Manville",
"Mule-Hide Products",
"Versico"
]
},
"Steep Slope Roofing": {
"Concrete & Clay Roof Tiles": [
"Vande Hey Raleigh"
],
"Asphalt Shingles": [
"CertainTeed",
"GAF",
"Owens Corning"
]
},
"Windows & Doors": {
"Replacement Windows": [
"Pella"
],
"New Construction Windows": [
"Pella"
],
"Exterior Doors": [
"Pella"
],
"Skylights": [
"Velux"
]
},
"Siding": {
"Vinyl Siding": [
"Mastic Home Exteriors"
]
}
},
"branchDetails": {
"branchNumber": "1"
}
};
document.getElementById("demo").innerHTML = obj.productListing['Roofing Insulation']['Roofing Insulation'];
<p id="demo"></p>