首页 > 解决方案 > 反应原生 iOS - JSON VALUE '' nsnull 类型的 ' 不能转换为有效的 url

问题描述

每次我在插入新邮件和密码后通过 expo 注册应用程序时,都会看到此屏幕。 这是屏幕错误

即使在我关闭博览会结束后再次打开它也会显示相同的红色屏幕和消息。但是,如果我关闭项目(通过摇动刷新它)并再次进入整个项目,现在有了一个现有的用户,它到目前为止工作得很好......(仍然需要修复)。


这是 **Register.js页面代码:**

import React, { Component } from "react";
import { View, Button, StyleSheet, TextInput, Alert, AsyncStorage } from "react-native";

const URL = 'http://185.60.170.14/plesk-site-preview/ruppinmobile.ac.il/site17/WebService.asmx';

export default class Register extends Component {
  state = {
    email: "",
    password: "",
    repassword: ""
  };

  Register = () => {
    if(this.state.password != this.state.repassword){
      Alert.alert(
        "Error",
        'Password does not match',
        [{ text: "OK", onPress: () => null }],
        { cancelable: false }
      );
      this.setState({password: '', repassword: ''});
      return;
    }


    let data = {
      email: this.state.email,
      password: this.state.password
    };

    fetch(URL + "/Register", {
      // בקשה לשרת למתודה Register
      body: JSON.stringify(data), // שליחת פרמטרים
      method: "POST",
      headers: {
        "Content-type": "application/json; charset=UTF-8"
      }
    })
      .then(res => {
        return res.json();
      })
      .then(userData => {
        console.log(userData.d);
        
        if (userData.d == "Error: This email is already in use") {
          Alert.alert(
            "Error",
            userData.d,
            [{ text: "OK", onPress: () => null }],
            { cancelable: false }
          );
        } else {
          AsyncStorage.setItem("@KnowingFriends:user", userData.d);
          this.props.navigation.navigate("MainApp");
        }
      })
      .catch(err => {
        console.error(err);
      });
  };

  render() {
    return (
      <View style={styles.container}>
        <TextInput
          style={styles.input}
          onChangeText={text => this.setState({ email: text })}
          value={this.state.email}
          placeholder="Email"
        />

        <TextInput
          style={styles.input}
          onChangeText={text => this.setState({ password: text })}
          value={this.state.password}
          secureTextEntry={true}
          placeholder="Password"
        />

        <TextInput
          style={styles.input}
          onChangeText={text => this.setState({ repassword: text })}
          value={this.state.repassword}
          secureTextEntry={true}
          placeholder="Repeat Password"
        />

        <Button onPress={this.Register} title="Submit" color="#841584" />
        <Button
          onPress={() => {
            this.props.navigation.navigate("Login");
          }}
          title="Go back"
          color="#841584"
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center"
  },
  input: {
    height: 40,
    width: 300,
    borderColor: "gray",
    borderWidth: 1
  }
});

我该如何解决这个问题?

标签: iosreactjsreact-nativeexpoasyncstorage

解决方案


我也有同样的问题,但我修复了

state = {
    text: '',
    image: null,
  };

改变了

state = {
text: '',
image: '',
  };


推荐阅读