我为体育创建了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正在增加。
答案 0 :(得分:-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.
}