我实际上是试图解析一个JSON对象与Xcode8.1上的Swift3。 这是我的代码:如何检查字段类型是否有?是没有ØNSNull
if let objData = objJson["DATA"] as! NSDictionary? {
var msg: String = ""
if let tmp = objData.object(forKey: "Message") {
msg = tmp as! String
} else {
print("NIIILLLLL")
}
}
我收到此错误信息:Could not cast value of type 'NSNull' (0x4587b68) to 'NSString' (0x366d5f4)
在该行msg = tmp as! String
。
我不理解为什么我得到这个错误,因为TMP的类型是Any
,它应该显示打印的,而不是转换tmp as! String
谢谢你的帮助,