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

时间:2016-11-26 04:07:23

标签: android ios json firebase react-native

我的反应原生Firebase APL出现了一个奇怪的错误。

react-native run-android正常工作没有错误。

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

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

我认为Firebase Class在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

2 个答案:

答案 0 :(得分:0)

我在这个BUG中深入调试。 最后我发现如下。

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

我没想到会出现这种错误。

谢谢Shoji

答案 1 :(得分:0)

向@itagaki寻求帮助。在以下代码中将单引号替换为双引号后,错误已消除

const BoldText = (props) => <Text style={{fontWeight: 'bold'}}>{props.children}</Text>;