JSON value '<null>' of type NSNull cannot be converted to NSString

Ali picture Ali · Nov 30, 2018 · Viewed 9.3k times · Source

I am getting the following error screen sometimes when I reload my React Native app in iOS Simulator.

enter image description here

Sometimes it doesn't happen at all but sometimes a few times during the day.

I am using SignalR client in my app as well as Firebase Messaging.

I have tried to put a try catch blocks to all of my app including where I use AsyncStorage but this is still happening.

Very frustrating.

Answer

Mahdieh Shavandi picture Mahdieh Shavandi · Mar 4, 2019

my problem was with source of the images that i had in my component. i had tell the image components to pass null as source while response of the server for the image was empty or null. means:

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

it was ok with android but in ios i ran into this error. so i changed my code to following and it's working fine now.

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

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