gpt4 book ai didi

ios - 无法将类型 'NSNull' (0x10aa1b600) 的值转换为 'NSString' (0x10b4dab48)

转载 作者:搜寻专家 更新时间:2023-11-01 05:45:52 25 4
gpt4 key购买 nike

我的 json 有餐厅的 googleplus 链接,如果餐厅没有任何 googleplus 链接,它会显示 null 但我收到如上所述的错误。

if dict["googlepluslink"] != nil
{
self.googlepluslink.append((dict["googlepluslink"] as? String)!)
}
else
{
self.googlepluslink.append(("-" as? String)!)
}

Could not cast value of type 'NSNull' (0x10aa1b600) to 'NSString' (0x10b4dab48)

最佳答案

使用 if letguard 语句来检查 dict["googlepluslink"] 是否为 String 然后根据它你可以追加你的数据如下所示

if let link = dict["googlepluslink"] as? String 
{
self.googlepluslink.append(link)
}
else {
self.googlepluslink.append("-")
}

关于ios - 无法将类型 'NSNull' (0x10aa1b600) 的值转换为 'NSString' (0x10b4dab48),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38368443/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com