我想要创建一个 if 语句来检查我的 JSON (item_section) 的某个键是否有空值。
这段代码:
let my_dict = item_section[counter].dictionaryValue
print(my_dict["creator"])
当未设置创建者时,打印:Optional(null)
。
如果设置了,则打印创建者的姓名,例如:user_729834892
。
如何制作 if 语句来检查创建者是否为 null?
如:
if ((my_dict["creator"]) == nil) { //This line does not work
my_dict["creator"] = "No Maker"
}
最佳答案
尝试
if my_dict["creator"].type == .Null {
print("creator is null")
}
关于json - 检查 JSON 作为字典是否包含Optional(null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38018351/