Skip to content

Instantly share code, notes, and snippets.

@sergdort
Last active December 16, 2015 12:08
Show Gist options
  • Save sergdort/a3dd93f024185c46543c to your computer and use it in GitHub Desktop.
Save sergdort/a3dd93f024185c46543c to your computer and use it in GitHub Desktop.
public typealias JSON = AnyObject
public typealias JSONDictionary = Dictionary<String, JSON>
public typealias JSONArray = Array<JSON>
public func JSONObjectWithData(data: NSData) -> AnyObject? {
do { return try NSJSONSerialization.JSONObjectWithData(data, options: []) }
catch { return .None }
}
public func JSONString(object: JSON) -> String? {
return object as? String
}
public func JSONObject(object: JSON) -> JSONDictionary? {
return object as? JSONDictionary
}
public func JSONObjects(object:JSON) -> [JSONDictionary]? {
return object as? [JSONDictionary]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment