本文介绍了无法将'NSNull'(0x10aa1b600)类型的值转换为'NSString'(0x10b4dab48)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的json有餐馆的googleplus链接,如果餐厅没有任何googleplus链接,它显示null但是我得到如上所述的错误。
My json has googleplus links of restaurants and it shows null if restaurant does not have any googleplus link But I get error of as mentioned above.
if dict["googlepluslink"] != nil { self.googlepluslink.append((dict["googlepluslink"] as? String)!) } else { self.googlepluslink.append(("-" as? String)!) }
无法转换类型'NSNull'的值(0x10aa1b600)到'NSString'(0x10b4dab48)
Could not cast value of type 'NSNull' (0x10aa1b600) to 'NSString' (0x10b4dab48)
推荐答案
使用如果让或保护要检查的语句 dict [googlepluslink] 是否为String,然后根据你可以附加如下数据
use if let or guard statement to check dict["googlepluslink"] is String or not and then according to that you can append your data like below
if let link = dict["googlepluslink"] as? String { self.googlepluslink.append(link) } else { self.googlepluslink.append("-") }更多推荐
无法将'NSNull'(0x10aa1b600)类型的值转换为'NSString'(0x10b4dab48)
发布评论