我與下文提到的格式的JSON文件訪問第一或特定對象如何從JSON數據
mydata.json
{
"nodes":{
"Aidan":{"color":"green", "shape":"dot", "alpha":1, "id" : "aidan"},
"Sofia":{"color":"green", "shape":"dot", "alpha":1},
"Liam":{"color":"GoldenRod", "shape":"dot", "alpha":1}
},
"edges":{
"Quinn":{
"Liam":{"length":2.5,"weight":2},
"Audrey":{"length":2.5,"weight":2},
"Noah":{"length":2.5,"weight":2},
"Claire":{"length":2.5,"weight":2}
},
"Liam":{
"Sofia":{"length":2.5,"weight":2},
"Ethan":{"length":2.5,"weight":2},
"Amelia":{"length":2.5,"weight":2}
}
}
}
下面
如所提到的,我將讀取上述使用jquery文件數據var data = $.getJSON("data/mydata.json",function(data){
var nodes = data.nodes;
var edges = data.edges;
//i want to access first element or between element.
//like var edge = edges.get(0) or nodes.get("aidan")
})
我想要訪問第一元件或元件之間與索引或通過對象的名稱屬性。像var edge = edges.get(0)或nodes.get(「aidan」)。
感謝
沒有「第一」的元素,它的所有對象,並且在對象沒有訂單,僅鍵和值。換句話說,不能保證一個鍵/值對出現在另一個之前。要獲得鍵的值,請使用點或括號表示法,而不要使用jQuery方法。 – adeneo