0

可能重复:
使用 jQuery 从 JSON 数组中获取唯一结果

我为运动创建了 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"
    }
]

我想使用 jQuery 获取唯一的 parentSportName,但我想知道我的 JSON 结构是否正确或者我需要做一些修改。我需要在创建嵌套列表时重新获取值,并且我的 SLOC 正在增加。

4

1 回答 1

-2

这可能会为您做到:

var myobj;
try{
myobj=[{"sportName":"Men's Basketball","path":"mbasket","sportID":7,"parentSportName":"Basketball"},{"sportName":"Women's BasketBall","path":"wcc","sportID":8,"parentSportName":"Basketball"}];
}

if (myobj==undefined){
//json data has problem.
}
于 2012-12-04T10:34:01.610 回答