无法将'NSNull'(0x10aa1b600)类型的值转换为'NSString'(0x10b4dab48) [英] Could not cast value of type 'NSNull' (0x10aa1b600) to 'NSString' (0x10b4dab48)

查看:116
本文介绍了无法将'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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆