0

我正在为运动和子运动创建 JSON,如下所示:

{
    "sportName": "Men's Basketball",
    "path": "mbasket",
    "sportID": 7,
    "parentSportName": "Basketball"
}, {
    "sportName": "Women's BasketBall",
    "path": "wcc",
    "sportID": 8,
    "parentSportName": "Basketball"
}, {
    "sportName": "Women's Cross Country",
    "path": "wbasket",
    "sportID": 9,
    "parentSportName": "Cross Country"
}, {
    "sportName": "Men's Cross Country",
    "path": "mcc",
    "sportID": 10,
    "parentSportName": "Cross Country"
}

现在我想将sportName 嵌套在 parentSportName 下,即 Cross Country 将包含 Men's Cross country 和 Women's Cross Country。我需要对 JSON 进行哪些更改?

PS:我正在创建一个嵌套列表

4

1 回答 1

0

添加包含嵌套运动数组的父运动的顶级数组。此示例通过 json lint 验证器。

var parentSports= 
    [
      {
         "parentSportName": "Basketball",
         "sports":[
           {
             "sportName": "Men's Basketball",
             "path": "mbasket",
             "sportID": 7
           }, {
             "sportName": "Women's BasketBall",
             "path": "wcc",
             "sportID": 8
           }]
      },{
         "parentSportName": "Cross Country",
         "sports": [
            {
             "sportName": "Women's Cross Country",
             "path": "wbasket",
             "sportID": 9
            }, {
             "sportName": "Men's Cross Country",
             "path": "mcc",
             "sportID": 10
            }]
      }
    ];

示例:http: //jsfiddle.net/Jrf37/

于 2012-12-04T10:18:19.500 回答