ios - JSON 值NSNull 类型的不能在 react native 中转换为 NSString
问题描述
当我在我的应用程序的主屏幕上登陆时,我一直遇到这个问题,我不是 100% 为什么会发生问题或可能是什么原因。我试过用谷歌搜索,但没有发现任何可以引导我走上正确道路的有用信息。
认为它发生在这段代码的某个地方:
const InstaagramEmpty = () => <InstagramUsersEmpty text="No matching users found" />
const InstagramUserItem = (props: { onSelect: () => void, user: InstagramUser }) => {
//TOOD: user button
return <AccountContainer onPress={props.onSelect}>
<AccountImage source={{ uri: props.user.photoUrl }} />
<Text text={props.user.username} />
</AccountContainer>
}
// Brinds image/text together
const SelectionContainer = styled(Row)`
`
const SelectionClear = styled(ButtonIcon)`
width:45px;
height:45px;
`
const InstagramUserSelection = (props: { onSelect: () => void, user: InstagramUser }) => {
return <Row drop>
<SelectionContainer>
<AccountImage source={{ uri: props.user.photoUrl }} />
<Text text={props.user.username} />
</SelectionContainer>
<SelectionClear icon={IconClose} iconTint={Colors.GreyDark} onPress={props.onSelect} />
</Row>
}
解决方案
当您的 JSON 文档包含值 null 时,它将被转换为 NSNull 类的 Objective-C 对象。NSNull 是一个单例类;类方法 [NSNull null] 总是返回唯一存在的 NSNull 对象。如果给你一个未知类型的对象,你可以通过与 [NSNull null] 比较来检查它是否为 JSON null 值。if (myJSONObject == [NSNull null]) ...
所以你的 JSON 数据包含一个空值,它变成了 [NSNull null],并且 [NSNull null] 不能转换成任何东西。和 nil 一样处理。例如如果 (myJSONObject == nil || myJSONObject == [NSNull null]) ...
推荐阅读
- c - Linux获取给定PID的进程开始时间
- sql - Pentaho 计算器步骤未获取正确的结果
- php - 使用PHPSpreadsheet将excel导入mysql时跳过值
- c# - C# Reg_Binary 和 BATCH
- c# - C# Bitmap.Save() 使用 Format16BppIndexed 给出 GDI+ 通用错误,并且没有给定方法有效
- select - 使用pyspark在collect_set之后按值选择行
- opengl - 20 面 DnD 骰子的顶点
- modx - 如何在 modx 中创建测验
- ios - 单击链接会冻结应用程序
- java - Gson 序列化程序将出生日期更改为前一天