Created
June 15, 2016 16:25
-
-
Save charleshkang/4924240bfcac6e94c7725ccc545ac4f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class func parseBadgeJSON () | |
{ | |
let jsonURL = "http://www.khanacademy.org/api/v1/badges" | |
if let url = NSURL(string: jsonURL) { | |
if let data = try? NSData(contentsOfURL: url, options: []) { | |
let json = JSON(data: data) | |
fetchBadgeJSON(json) | |
} | |
} | |
} | |
class func fetchBadgeJSON(json: JSON) | |
{ | |
for (_, result) in json { | |
let title = result["description"].stringValue | |
let smallIcon = result["icons"]["small"].stringValue | |
let category = result["badge_category"].stringValue | |
let points = result["points"].stringValue | |
let obj = ["title": title, "icon": smallIcon, "category": category, "points": points] | |
objects.append(obj) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment