Skip to content

Instantly share code, notes, and snippets.

@LeonardoCardoso
Last active October 30, 2018 09:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeonardoCardoso/cb228a1bb439b91d2492 to your computer and use it in GitHub Desktop.
Save LeonardoCardoso/cb228a1bb439b91d2492 to your computer and use it in GitHub Desktop.
import Foundation
extension String {
var parseJSON: AnyObject? {
let data = self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
if let jsonData = data {
do {
return try NSJSONSerialization.JSONObjectWithData(jsonData, options: NSJSONReadingOptions.MutableContainers)
} catch _ {
return nil
}
} else {
return nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment