How to check if JSON is null in swift?
if ((nullObject as? NSNull) == nil) {
...
}
Try something like this:
Swift code:
if let outcome = dict["outcome_status"] as? NSDictionary {
//Now you know that you received a dictionary(another json doc) and is not 'nil'
//'outcome' is only valid inside this if statement
if let category = outcome["category"] as? String {
//Here you received string 'category'
outcomeStatusLabel.text = category
outcomeStatusLabel.font = UIFont.systemFontOfSize(14.0)
outcomeStatusLabel.numberOfLines = 0
}
if let date = outcome["date"] as? String {
//Here you received string 'date'
outcomeDateLabel.text = date
outcomeDateLabel.font = UIFont.systemFontOfSize(14.0)
outcomeDateLabel.numberOfLines = 0
}
}
This is a safe way to work with Json.