Jeson解析错误:意外的Eof

时间:2018-02-20 05:00:48

标签: javascript php react-native

我是反应原生的新手。我正面对jeson perse error: unexpected eof。我只想做一个注册表。首先,我打开一个新项目并编辑它,然后运行到模拟器然后得到此错误。是否有必要添加任何内容以在服务器中发送数据。

请帮帮我

这是我的代码:

import React, { Component } from 'react';
import {
	AppRegistry,
  Platform,
  StyleSheet,
  Text,
  View,Button,TextInput
} from 'react-native';



export default class App extends Component {
	 constructor(props){
	 	super(props)
		this.state={
			username:'',
			useremail:'', userpassword:'',userpasswordagain:''
		}
	 
	 }

userRegister= () =>{
	//alert('ok');
	const{username}=this.state;
	const{useremail}=this.state;
	const{userpassword}=this.state;
	const{userpasswordagain}=this.state;
//http://localhost/reactnative/registration2.php
//https://akhterruby91.000webhostapp.com/registration2.php
fetch('https://akhterruby91.000webhostapp.com/registration2.php',{

	method: 'POST',
	headers: new Headers({
		'Accept':'application/jason',
		'Content-Type': 'application/jason'
	}),
	body: JSON.stringify({
		username: username,
		useremail: useremail,
		userpassword: userpassword,
		userpasswordagain: userpasswordagain,
	})
}).then((response) => response.json())

      .then((responseJson) => {
 
// Showing response message coming from server after inserting records.
        Alert.alert(responseJson);
 
      }).catch((error) => {
        console.error(error);
      });
 
}




  render() {
    return (
      <View style={styles.container}>

<TextInput
placeholder="Enter Name"
onChangeText={username => this.setState({username})}
style={{width: 200, margin: 10}}

/>

<TextInput
placeholder="Email"
onChangeText={useremail => this.setState({useremail})}
style={{width: 200, margin: 10}}

/>

<TextInput
placeholder="Password"
onChangeText={userpassword => this.setState({userpassword})}
style={{width: 200, margin: 10}}

/>

<TextInput
placeholder="Password Again"
onChangeText={userpasswordagain => this.setState({userpasswordagain})}
style={{width: 200, margin: 10}}

/>

<Button title="singup" onPress={this.userRegister} color="green"/>


<Text style={styles.instructions}>
          To login please click.
 </Text>

  </View>
  
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('App', () => App);

这是我的注册表格代码:

<?php
 
// Importing DBConfig.php file.
include 'connection.php';
 
// Creating connection.
 $con = mysqli_connect($mysql_host, $mysql_username, $mysql_password,$mysql_db);
 
 // Getting the received JSON into $json variable.
 $json = file_get_contents('php://input');
 
 // decoding the received JSON and store into $obj variable.
 $obj = json_decode($json,true);
 
 // Populate User name from JSON $obj array and store into $name.
$name = $obj['username'];
 
// Populate User email from JSON $obj array and store into $email.
$email = $obj['useremail'];
 
// Populate Password from JSON $obj array and store into $password.
$password = $obj['userpassword'];
 $passwordagain = $obj['userpasswordagain'];
//Checking Email is already exist or not using SQL query.
$CheckSQL = "SELECT * FROM registration_info WHERE email='$email'";
 
// Executing SQL Query.
$check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
 
 
if(isset($check)){
 
 $EmailExistMSG = 'Email Already Exist, Please Try Again !!!';
 
 // Converting the message into JSON format.
$EmailExistJson = json_encode($EmailExistMSG);
 
// Echo the message.
 echo $EmailExistJson ; 
 
 }
 else{
 
 // Creating SQL query and insert the record into MySQL database table.
$Sql_Query = "INSERT into registration_info  values ('',$name','$email','$password')";
 
 
 if(mysqli_query($con,$Sql_Query)){
 
 // If the record inserted successfully then show the message.
$MSG = 'User Registered Successfully' ;
 
// Converting the message into JSON format.
$json = json_encode($MSG);
 
// Echo the message.
 echo $json ;
 
 }
 else{
 
 echo 'Try Again';
 
 }
 }
 mysqli_close($con);
?>

问题在于:  Image of the problem

请帮帮我,谢谢。

0 个答案:

没有答案