Created
June 29, 2014 13:43
-
-
Save pketh/b5c56638be87cf159fe0 to your computer and use it in GitHub Desktop.
JSON with Swift
This file contains hidden or 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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
from http://stackoverflow.com/a/24094777/2318064