考慮下面的JSON對象數組:的Javascript JSON對象的多級陣列 - 如何訪問鍵值對在第二級別或更高級別
myList = [
{title:"Parent1",
children:[{childname:"Child11"},
{childname:"Child12"}],
cars:[{carname:"Car11"},
{carname:"Car12"}]
},
{title:"Parent2",
children:[{childname:"Child21"},
{childname:"Child22"}],
cars:[{carname:"Car21"},
{carname:"Car22"}]
}
];
如何做一個訪問「Child21」在JavaScript?下列選項不工作:
var myString = myList[1].children[0].childname; //Does not work
var myString = myList[1]["children"][0].childname; //Does not work
UGH ***代碼格式請! – Zoidberg 2009-10-30 14:26:00
你的第一個例子'myList [1] .children [0] .childname' * does * work。 – 2009-10-30 14:26:37
你的意思是carname ... right crecentfresh ... 把這個答案,我會投它 – Zoidberg 2009-10-30 14:27:39