Javascript - read JSON Array without square brackets
本问题已经有最佳答案,请猛点这里访问。
所以我得到了这个JSON对象。我想遍历
如果我知道名字,我可以一个接一个地访问,例如:
但是我如何迭代它们呢?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | 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: {} } } |
你可以用这段代码
1 2 3 4 5 6 7 | 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 } } |