Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swiftyJSON check if value is null

I have a json which is array of dictionary

response.text = [{
"id": "4635465675",
"name": "Arts",
"pluralName": "Arts",
"shortName": null
}]

json = JSON((response.text)?.data(using: .utf8)) How can i check is value for key "shortName" null or not, say for first dictionary in the array ? I tried to do like this

if json[0]["shortName"] is NSNull

But it's always true. How can i handle it?

like image 706
Michael Avatar asked Mar 05 '18 09:03

Michael


1 Answers

you can directly check as the key of JSON.null

if json[0]["shortName"] == JSON.null {
// show the alert

}

if its your String

if json[0]["shortName"].string == nil {
like image 178
Anbu.Karthik Avatar answered Oct 13 '22 15:10

Anbu.Karthik