0

Possible Duplicate:
Get unique results from JSON array using jQuery

I have created JSON for sports which looks like

 [
    {
        "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"
    }
]

I want to fetch unique parentSportName using jQuery, but what I wanted to know if my JSON structure is correct or I need to do some modifications. I need to re fetch the values as am creating nested list and my SLOC is increasing.

4
  • Refer to the below link stackoverflow.com/questions/6680430/… Commented Dec 4, 2012 at 10:23
  • That particular json isn't valid. Wrap the entire json in [] and it'll pass as a JsonArray with JSON objects inside. You can always lint your json @ jsonlint.com Commented Dec 4, 2012 at 10:28
  • @laxonline I checked it. But I am creating a nested list so I need to refetch elements corresponding to parentSportName again. I have restrictions on SLOC. Commented Dec 4, 2012 at 10:28
  • check it with jsonlint.com for validity Commented Dec 4, 2012 at 10:29

1 Answer 1

-2

This might do it for you:

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.
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.