Last active
October 30, 2018 09:59
-
-
Save LeonardoCardoso/cb228a1bb439b91d2492 to your computer and use it in GitHub Desktop.
This file contains 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
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