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

编程入门 行业动态 更新时间:2024-10-09 02:28:55
本文介绍了无法将'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)

本文发布于:2023-11-26 05:15:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632778.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   类型   NSNull   NSString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!