以下是我的JSON。我想在這個對象中獲得數組和數組的名稱。這是動態創建的,所以我不知道它的數量和名稱。這裏是這個例子中的2個數組,名爲Table和Table1。如何獲取JSON對象中的數組數量
"{
"Table": [
{
"Day": "Jan",
"Counts": 20,
"SrNo": 1,
"Title": "test2",
"ProfilePic": "/Image1.jpg"
},
{
"Day": "Feb",
"Counts": 10,
"SrNo": 2,
"Title": "test2",
"ProfilePic": "/Image1.jpg"
}
],
"Table1": [
{
"Day": "01",
"Counts": 5,
"SrNo": 1,
"Title": "test3",
"ProfilePic": "/Image2.jpg"
},
{
"Day": "02",
"Counts": 9,
"SrNo": 2,
"Title": "test3",
"ProfilePic": "/Image2.jpg",
}
]
}"
能夠保證所有的陣列將只對第一個「級別」,並不是嵌套對象? – Phillip
感謝您的答案,我的情況我需要json.stringify即,Object.keys(JSON.parse(obj))。length; –
[獲取Json對象上的項目總數?](https://stackoverflow.com/questions/13782698/get-total-number-of-items-on-json-object) –