JSON给了我错误的json消息

时间:2017-12-10 14:17:15

标签: php json react-native

如果这篇文章中有任何不清楚的地方,我准备回答它,但请帮我解决。我试图从response.json中删除'()'这是JSON MESSAGE当我发生时这个。当我添加response.json()时,它会给我意想不到的令牌'<'

这是react-native fetch

fetch('url',{
        method:'post',
        header:{
            'Accept': 'application/json',
            'Content-type': 'application/json'
        },
        body:JSON.stringify({
            // we will pass our input data to server
            username: userEmail,
            password: userPassword
        })

    })
    .then((response) => response.json)
     .then((responseJson)=>{
         if(responseJson == "ok"){
             // redirect to profile page
             alert("Successfully Login");
             this.props.navigation.navigate("Profile");
         }else{
             alert(responseJson);
         }
     })
     .catch((error)=>{
     console.error(error);
     });

PHP文件:

 include 'config.php';

$json = file_get_contents('php://input');   
$obj = json_decode($json,true);

$username = $obj['username'];

$password = $obj['password'];

if($obj['username']!=""){   

    $check_user="SELECT * FROM logintest where username='$username' and password='$password'";
$result= mysqli_query($con,$check_user);




    if($result->num_rows==0){

          $MSG = 'Wrong Details' ;


          $json = json_encode($MSG);


               echo $json ;         
    }

有人可以帮我解决问题。

0 个答案:

没有答案