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?
if json["shortName"] is nil
. orif let shortName = json["shortName"] { print("shortName - \(shortName)") } else { print("shortName is nil") }
– Liujson[0]["shortName"] is NSNull
But it's always true. How can i handle it? off course it will be true because its null – Consciousif json[0]["shortName"] is NSNull { SHORT NAME IS NULL } else { NOT NULL }
, its a working code – Consciousjson
– Liu[{ "id": "4635465675", "name": "Arts", "pluralName": "Arts", "shortName": null }]
and json variablevar json = JSON((response.text)?.data(using: .utf8))
– Complacent[{ "id": "4635465675", "name": "Arts", "pluralName": "Arts", "shortName": null }]
– Complacent