Skip to content

Instantly share code, notes, and snippets.

@rackaam
Created March 8, 2015 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rackaam/da9277c8dfb763a70ebe to your computer and use it in GitHub Desktop.
Save rackaam/da9277c8dfb763a70ebe to your computer and use it in GitHub Desktop.
var o = JSON.parse('{"code": 0,"court": {"Set": { "1": { "A": 0, "B": 6 }, "2": { "A": 0, "B": 0 } }, "TeamA": "BEL", "NameA": "E.DOM", "ScoreA": "0", "Duration": "02:31", "Winner": null, "Tableau": "1/2-P", "Category": "SW", "Court": 6, "TeamB": "DEU", "NameB": "A.FUCHS", "ScoreB": "40", "Service": "B" }}');
// Afficher nom de la team A
console.log(o.court.TeamA);
// Afficher le score de tous les sets
var sets = o.court.Set;
for(id in sets){
console.log("Set " + id + " A:" + sets[id].A);
console.log("Set " + id + " B:" + sets[id].B);
}
// Verifier si un set existe :
var set = 3;
if(set in o.court.Set){
console.log("Set " + set + " existe");
}else{
console.log("Set " + set + " n'existe pas");
}
@rackaam
Copy link
Author

rackaam commented Mar 8, 2015

le texte en paramètre de JSON.parse est le résultat de la requête à l'api ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment