ios - NSNull 类型的 JSON 值 '<null>' 无法转换为 NSString

标签 ios react-native simulator

当我在 iOS 模拟器中重新加载我的 React Native 应用程序时,有时会出现以下错误屏幕。

enter image description here

有时根本不会发生,但有时一天会发生几次。

我在我的应用程序中使用 SignalR 客户端以及 Firebase Messaging。

我尝试将try catch block 放入我的所有应用程序,包括我使用 AsyncStorage 的地方,但这种情况仍在发生。

非常沮丧。

最佳答案

我的问题是我的组件中的图像来源。我已经告诉图像组件将 null 作为源传递,而服务器对图像的响应为空或 null。意思是:

<Image source={{uri: null}} style={styles.myImageStyle}/>

在 android 上没问题,但在 ios 上我遇到了这个错误。所以我将我的代码更改为以下,现在工作正常。

const imageUri = myImageUri!=null ? myImageUri : ""

<Image source={imageUri.length!=0?{uri: imageuri}: null} style={styles.myImageStyle}/>

关于ios - NSNull 类型的 JSON 值 '<null>' 无法转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53550292/

相关文章:

objective-c - TableView 背景图像遍历单元格文本标签

ios - 警报中预加载的文本

c# - ObjC 与 MonoTouch float 和数组性能

react-native - 如何在 react-native 中重叠

java - 启动 openday light netconf testtool 模拟器时出错

ios - 使用前置摄像头进行手势检测

javascript - 删除按钮轮廓 native 基础

react-native - React Native Webview 处理 url 更改监听器

XCode 4.3 通过输入自动在 TextView 中从剪贴板文本

iphone - 检测模拟器的类型