Skip to content

Instantly share code, notes, and snippets.

@charleshkang
Created June 15, 2016 16:25
Show Gist options
  • Save charleshkang/4924240bfcac6e94c7725ccc545ac4f8 to your computer and use it in GitHub Desktop.
Save charleshkang/4924240bfcac6e94c7725ccc545ac4f8 to your computer and use it in GitHub Desktop.
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