Skip to content

Instantly share code, notes, and snippets.

@pketh
Created June 29, 2014 13:43
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 pketh/b5c56638be87cf159fe0 to your computer and use it in GitHub Desktop.
Save pketh/b5c56638be87cf159fe0 to your computer and use it in GitHub Desktop.
JSON with Swift
func getJSON(urlToRequest: String) -> NSData{
return NSData(contentsOfURL: NSURL(string: urlToRequest))
}
func parseJSON(inputData: NSData) -> NSDictionary{
var error: NSError?
var boardsDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(inputData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
return boardsDictionary
}
var request = "http://date.jsontest.com"
var x = getJSON(request)
var y = parseJSON(x)
println(y)
@pketh
Copy link
Author

pketh commented Jun 29, 2014

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