android - NSnull 类型的 JSON 值无法转换为 NSString

标签 android ios json firebase react-native

我的 react-native Firebase APL 出现奇怪的错误。

react-native run-android 运行良好,没有错误。

但是 react-native run-ios 失败,NSnull 类型的 JSON 值无法转换为 NSString。

源代码如下。(在firebase上进行身份验证的主要和注册类)

我认为 Firebase 类在 ios 和 Android 上有不同的 ACT 将 JSON 转换为文本。

任何建议表示赞赏。

商事

主要

//在此处初始化 firebase 应用程序,并根据需要将其传递给其他组件。仅在启动时初始化。

    const firebaseApp = firebase.initializeApp(firebaseConfig);

    var GiftedMessenger = require('react-native-gifted-messenger');

    let styles = {}

    class Pricing extends Component {

    constructor(props){

    super(props);

    this.state = {

    page: null

    };

    /* this.itemsRef = this.getRef().child('items'); */

    }

    componentWillMount(){

    // We must asynchronously get the auth state, if we use currentUser here, it'll be null

    const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) => {

    // If the user is logged in take them to the accounts screen

    if (user != null) {

    this.setState({page: Account});

    console.log('(user != null)')

    return;

    }

    // otherwise have them login

    console.log('(user != Login)')

    this.setState({page: Login});

    // unsubscribe this observer

    unsubscribe();

    });

    }

    render() {

    if (this.state.page) {

    return (

    // Take the user to whatever page we set the state to.

    // We will use a transition where the new page will slide in from the right.

    <Navigator

    initialRoute={{component: this.state.page}}

    configureScene={() => {

    return Navigator.SceneConfigs.FloatFromRight;

    }}

    renderScene={(route, navigator) => {

    if(route.component){

    // Pass the navigator the the page so it can navigate as well.

    // Pass firebaseApp so it can make calls to firebase.

    return React.createElement(route.component, { navigator, firebaseApp});

    }

    }} />

);

} else {

return (

// Our default loading view while waiting to hear back from firebase

最佳答案

我在这个BUG中深度调试。 最后我找到了如下。

<Image
source={{uri: 'this.state.user.photoURL'}} <<<single quotation was added. 
style={styles.image}
/>

没想到会出现这种错误。

谢谢庄子

关于android - NSnull 类型的 JSON 值无法转换为 NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40814806/

相关文章:

javascript - 在 JavaScript 中嵌套的 JSON 对象中的父/子属性之间遍历

java - 如何使用http从Java后端在Angular前面显示一些数据

android - Android 中 Eclipse 的特定目标模拟器?

android - 如果手机可以上网,我们如何得到通知?

ios - 在 Swift 中使用 NSDate 无法正确获取日期

ios - 在 iPad 上使用 OpenCV 避免碰撞

ios - touchesbegan 用于关闭 ScrollView 下的键盘 TextView 不起作用

json - 如何清理进入 Sinatra 应用程序的所有参数?

java - 将上下文传递给 getColor,Android Studio

android - 找不到Gradle DSL方法: 'implementation()'(Android React Native)