1

我正在为网站上的临时表视图编写一些 JSON。以前从未写过 JSON,所以非常感谢一些帮助。

我需要显示船员名单,每年分成 18 人一组,然后分成 2 组,每组 9 个 ech,有 4 个属性。

层次结构看起来像这样:

  • 2013
    • 结果
    • 蓝色小船
      • 职位、姓名、学院、体重
      • (+8 更多)
    • 伊希斯(预备船)
  • 2012
  • 2011
  • (……自 1829 年以来)

这是我第一次尝试编写/格式化 JSON,因此请仅在您有帮助或有建设性的情况下发表评论。

JSON

{
"crews": [{
    "items": [
    {
        "year"      :   "2013",
        "boat"      :   "Blue",
        "position"  :   "1",
        "name"      :   "Patrick Close",
        "college"   :   "Pembroke",
        "weight"    :   "14st 2lbs"
    }, {
        "year"      :   "2013",
        "boat"      :   "Blue",
        "position"  :   "2",
        "name"      :   "Geordie Macleod",
        "college"   :   "Christ Church",
        "weight"    :   "13st 10lbs"
    }, {
        "year"      :   "2013",
        "boat"      :   "Isis",
        "position"  :   "1",
        "name"      :   "Iain Mandale",
        "college"   :   "Mansfield",
        "weight"    :   "11st 11lbs"
    }, {
        "year"      :   "2013",
        "boat"      :   "Isis",
        "position"  :   "2",
        "name"      :   "Nichola Hazell",
        "college"   :   "Christ Church",
        "weight"    :   "14st 9lbs"
    }]
}
}

这是否更好?

{
"crews": [
    {
        "year": [
            {
                "2013": [
                    {
                        "boat": [
                            {
                                "Blue": [
                                    {
                                        "boat"      :   "Blue",
                                        "position"  :   "1",
                                        "name"      :   "Patrick Close",
                                        "college"   :   "Pembroke",
                                        "weight"    :   "14st 2lbs"
                                    },
                                    {
                                        "boat"      :   "Blue",
                                        "position"  :   "2",
                                        "name"      :   "Geordie Macleod",
                                        "college"   :   "Christ Church",
                                        "weight"    :   "13st 10lbs"
                                    }
                                ],
                                "Isis": [
                                    {
                                        "boat"      :   "Isis",
                                        "position"  :   "1",
                                        "name"      :   "Iain Mandale",
                                        "college"   :   "Mansfield",
                                        "weight"    :   "11st 11lbs"
                                    },
                                    {
                                        "year"      :   "2013",
                                        "boat"      :   "Isis",
                                        "position"  :   "2",
                                        "name"      :   "Nichola Hazell",
                                        "college"   :   "Christ Church",
                                        "weight"    :   "14st 9lbs"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        ]
    }
]
}
4

1 回答 1

0

您的 JSON 无效。您可以在JSONLint.com对其进行测试,已修复:

{
    "crews": [
        {
            "items": [
                {
                    "year": "2013",
                    "boat": "Blue",
                    "position": "1",
                    "name": "Patrick Close",
                    "college": "Pembroke",
                    "weight": "14st 2lbs"
                },
                {
                    "year": "2013",
                    "boat": "Blue",
                    "position": "2",
                    "name": "Geordie Macleod",
                    "college": "Christ Church",
                    "weight": "13st 10lbs"
                },
                {
                    "year": "2013",
                    "boat": "Isis",
                    "position": "1",
                    "name": "Iain Mandale",
                    "college": "Mansfield",
                    "weight": "11st 11lbs"
                },
                {
                    "year": "2013",
                    "boat": "Isis",
                    "position": "2",
                    "name": "Nichola Hazell",
                    "college": "Christ Church",
                    "weight": "14st 9lbs"
                }
            ]
        }
    ]
}

如果您想更改输出,请显示您如何生成它以及您希望它看起来像什么的示例。

于 2013-10-21T14:57:58.850 回答