gpt4 book ai didi

Javascript - 读取不带方括号的 JSON 数组

转载 作者:行者123 更新时间:2023-12-03 06:51:31 27 4
gpt4 key购买 nike

所以我得到了这个 JSON 对象。我想迭代 nodes 中的所有对象但对象 nodes对象未格式化为 [] 的数组

如果我知道名称,我可以依次访问:

var X = Trend.L13

var node = X.nodes["AGENT.OBJECTS.House.SKL04_SK2.L13.Frost.AL01"]

但是我如何迭代它们呢?

var Trend = {


L13: {
dataArchive: "datavalues",
nodes: {
"AGENT.OBJECTS.House.SKL04_SK2.L13.Frost.AL01": {
visible: true,
axis: "left",
style: "Line",
color: "#66AF31",
linewidth: 1,
nonstop: true,
stairs: true,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.Frost.AL01",
text: "Frost"
},
"AGENT.OBJECTS.House.SKL04_SK2.L13.TempZul.MT01": {
visible: true,
axis: "right",
style: "Line",
color: "#8701AF",
linewidth: 1,
nonstop: true,
stairs: false,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.TempZul.MT01",
text: "Temp ZUL"
},
"AGENT.OBJECTS.House.SKL04_SK2.L13.PuWrg.SS01": {
visible: true,
axis: "left",
style: "Line",
color: "#000",
linewidth: 1,
nonstop: true,
stairs: true,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.PuWrg.SS01",
text: "PuWRG"
},
"AGENT.OBJECTS.House.SKL04_SK2.L13.TempWrgVl.MT01": {
visible: true,
axis: "right",
style: "Line",
color: "#FF2511",
linewidth: 1,
nonstop: false,
stairs: false,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.TempWrgVl.MT01",
text: "Temp. WRG Vorlauf"
},
"AGENT.OBJECTS.House.SKL04_SK2.L13.TempZulNachWRG.MT01": {
visible: true,
axis: "right",
style: "Line",
color: "#F99602",
linewidth: 1,
nonstop: false,
stairs: false,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.TempZulNachWRG.MT01",
text: "Temp. ZUL nach WRG"
},
"AGENT.OBJECTS.House.SKL04_SK2.L13.VtWrg.SS01": {
visible: true,
axis: "left",
style: "Line",
color: "#A5184A",
linewidth: 1,
nonstop: false,
stairs: true,
configname: "L13",
address: "AGENT.OBJECTS.House.SKL04_SK2.L13.VtWrg.SS01",
text: "VT WRG"
}
},
leftAxis: {
visible: "1",
autoScale: "1",
min: -3.7,
max: 37,
description: "Linke Achse"
},
rightAxis: {
visible: "1",
autoScale: "0",
min: 0,
max: 40,
description: "Rechte Achse"
},
time: {
startTime: 1453010899798,
endTime: 1453183699799,
lastTime: "1",
lastTimeValue: 2,
lastTimeUnit: "86400"
},
newnodes: {}
}
}

最佳答案

您可以使用这段代码

    var Nodes = Trend.L13.nodes;
for(var key in Nodes) {
if( Nodes.hasOwnProperty(key) ) {
console.log(Nodes[key]);
// Use Nodes[key] in this case to access individual objects
}
}

关于Javascript - 读取不带方括号的 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37477763/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com