什么是多维数组的最佳结构JSON结构

时间:2018-06-07 06:56:05

标签: arrays json multidimensional-array

我有以下excel表。 我想以json结构表示该表。

最好的结构是什么?

enter image description here

3 个答案:

答案 0 :(得分:2)

最佳结构?这取决于。一种方法是创建一个对象(单元格)数组。每个单元格包含“百分比”,“国家”,“性别”和“年份”等属性。这样您就可以轻松地对这些列进行排序。

另一种方法是创建仅具有X和Y属性的2d单元格数组,以显示它们在表格中的位置。您必须发送有关表格本身的一些信息。

答案 1 :(得分:0)

这是JSON结构。请检查并确认。

  {
    "men": [
      {
        "USA": [
          {
            "during12months": {
              "1997": "9.5%",
              "2002": "16.6%",
              "2012": "12.2%"
            },
            "earlier12months": {
              "1997": "8.3%",
              "2002": "7.8%",
              "2012": "22.9%"
            },
            "never": {
              "1997": "82.2%",
              "2002": "75.6%",
              "2012": "64.9%"
            }
          }
        ],
        "Europe": [
          {
            "during12months": {
              "1997": "9.2%",
              "2002": "14.4%",
              "2012": "13.7%"
            },
            "earlier12months": {
              "1997": "11.3%",
              "2002": "8.2%",
              "2012": "18.5%"
            },
            "never": {
              "1997": "79.5%",
              "2002": "77.4%",
              "2012": "67.8%"
            }
          }
        ]
      }
    ],
    "women": [
      {
        "USA": [
          {
            "during12months": {
              "1997": "12.1%",
              "2002": "15.5%",
              "2012": "13.4%"
            },
            "earlier12months": {
              "1997": "7.0%",
              "2002": "8.4%",
              "2012": "23.6%"
            },
            "never": {
              "1997": "80.9%",
              "2002": "76.1%",
              "2012": "63.0%"
            }
          }
        ],
        "Europe": [
          {
            "during12months": {
              "1997": "12.6%",
              "2002": "17.6%",
              "2012": "14.9%"
            },
            "earlier12months": {
              "1997": "8.8%",
              "2002": "8.2%",
              "2012": "16.9%"
            },
            "never": {
              "1997": "78.6%",
              "2002": "74.2%",
              "2012": "68.2%"
            }
          }
        ]
      }
    ],
    "total": [
      {
        "USA": [
          {
            "during12months": {
              "1997": "10.8%",
              "2002": "16.0%",
              "2012": "12.8%"
            },
            "earlier12months": {
              "1997": "7.7%",
              "2002": "8.1%",
              "2012": "23.3%"
            },
            "never": {
              "1997": "81.5%",
              "2002": "75.9%",
              "2012": "63.9%"
            }
          }
        ],
        "Europe": [
          {
            "during12months": {
              "1997": "11.0%",
              "2002": "16.0%",
              "2012": "14.3%"
            },
            "earlier12months": {
              "1997": "10.0%",
              "2002": "8.2%",
              "2012": "17.7%"
            },
            "never": {
              "1997": "79.0%",
              "2002": "75.8%",
              "2012": "68.0%"
            }
          }
        ]
      }
    ]
  }

使用列获取查询:

{
  "men": [
    { 
      "Europe": [
        {

          "earlier12months": {
            "1997": "11.3%",
            "2002": "8.2%",
            "2012": "18.5%"
          }

        }
      ]
    }
  ],
  "women": [
    {

      "Europe": [
        {

          "earlier12months": {
            "1997": "8.8%",
            "2002": "8.2%",
            "2012": "16.9%"
          }

        }
      ]
    }
  ],
  "total": [
    {

      "Europe": [
        {

          "earlier12months": {
            "1997": "10.0%",
            "2002": "8.2%",
            "2012": "17.7%"
          }
        }
      ]
    }
  ]
}

希望它能帮到你

由于 MUTHU

答案 2 :(得分:0)

for Harder version .. LOL!

enter image description here

来源:

{
 "rows": 
[
{ row:"Men", 
data:{ rows:[
{ row:"1997",data:{ 
cols:[ 
{ col:"USA", data: { 
cols:[ 
{ col:"during last 12", data:"9.5%"},
{ col:"earlier than 12", data:"9.5%"},
{ col:"never", data:"9.5%"} ] }}
,
{ col:"Europe", data: {}}] } },
{ row:"2002",data:{} },
{ row:"2002",data:{} }]  }}
,
{ row:"Women" }
,
{ row:"Total" }
]
}

好笑。