菜鸟教程小白 发表于 2022-12-11 18:10:00

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


                                            <p><p>我的 react-native Firebase APL 有一个奇怪的错误。</p>

<p>react-native run-android 工作正常,没有错误。</p>

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

<p>源代码如下。(主要和注册类在firebase上进行身份验证工作)</p>

<p>我认为 Firebase Class 在 ios 和 Android 上有不同的 ACT 来将 JSON 转换为文本。</p>

<p>任何建议表示赞赏。</p>

<p>商事</p>

<p>主要</p>

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

<pre><code>    const firebaseApp = firebase.initializeApp(firebaseConfig);

    var GiftedMessenger = require(&#39;react-native-gifted-messenger&#39;);

    let styles = {}

    class Pricing extends Component {

    constructor(props){

    super(props);

    this.state = {

    page: null

    };

    /* this.itemsRef = this.getRef().child(&#39;items&#39;); */

    }

    componentWillMount(){

    // We must asynchronously get the auth state, if we use currentUser here, it&#39;ll be null

    const unsubscribe = firebaseApp.auth().onAuthStateChanged((user) =&gt; {

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

    if (user != null) {

    this.setState({page: Account});

    console.log(&#39;(user != null)&#39;)

    return;

    }

    // otherwise have them login

    console.log(&#39;(user != Login)&#39;)

    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.

    &lt;Navigator

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

    configureScene={() =&gt; {

    return Navigator.SceneConfigs.FloatFromRight;

    }}

    renderScene={(route, navigator) =&gt; {

    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});

    }

    }} /&gt;

);

} else {

return (

// Our default loading view while waiting to hear back from firebase
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我在这个BUG中深度调试。
最后找到如下。</p>

<pre><code>&lt;Image
source={{uri: &#39;this.state.user.photoURL&#39;}} &lt;&lt;&lt;single quotation was added.
style={styles.image}
/&gt;
</code></pre>

<p>没想到会出现这种错误。</p>

<p>谢谢庄司</p></p>
                                   
                                                <p style="font-size: 20px;">关于android - NSnull 类型的 JSON 值无法转换为 NSString,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40814806/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40814806/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: android - NSnull 类型的 JSON 值无法转换为 NSString