<null> NSNull 类型的 JSON 值无法在 react native 中转换为 NSString



当我在应用程序的主屏幕上着陆时,我一直遇到这个问题,我不是100%为什么会出现这个问题,也不是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数据包含一个null值,该值变为[NSNull-null],并且[NSNull-null]不能转换为任何值。按零处理。例如,如果(myJSONObject==nil||myJSONObject==[NSNull null](。。。

最新更新