javascript – 如何获取JSON对象中的数组数

下面是我的JSON.我想在这个对象中获取数组的数量和名称.这是动态创建的,所以我不知道它的编号和名称.这个示例中有2个数组,名为Table和Table1.

"{
      "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",        
     }
   ]
 }"
最佳答案
试试下面提到的代码,

Object.keys(jsonObject).length;

另请参考……:Get total number of items on Json object?

得到所有的名字:

var keys = Object.keys(jsonObject); // this will return root level title ["Table" , "Table1"]

转载注明原文:javascript – 如何获取JSON对象中的数组数 - 代码日志