I am currently working on an app which brings back json, in the following format
\"location_subtype\" = \"somevalue\"; \"location_type\" = Force;
Try corresponding Swift class to following Objective C class,
dict["outcome_status"] != [NSNull null]
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.
in case you are using Alamofire and JSONSubscriptType use this:
if !(parsedJSON["someKey"] == JSON.null) {
//do your stuff
}
If you're using SwiftyJSON, just check .isEmpty() on the object to confirm if it's empty.
if ((nullObject as? NSNull) == nil) {
...
}