Java Can';t将JSON格式的数据从php检索到android

Java Can';t将JSON格式的数据从php检索到android,java,php,android,mysql,json,Java,Php,Android,Mysql,Json,它是一个寄存器函数。我可以将记录添加到我的数据库中。但是对于通过php脚本做出的响应,我无法显示响应或从php获取对Android的响应 当电子邮件被复制时,php应该以失败作为响应。。。。我怎样才能在android上显示它 register.php <?php include_once 'connection.php'; class User { private $db; private $connection; function __construct() { $this

它是一个寄存器函数。我可以将记录添加到我的数据库中。但是对于通过php脚本做出的响应,我无法显示响应或从php获取对Android的响应

当电子邮件被复制时,php应该以失败作为响应。。。。我怎样才能在android上显示它

register.php

<?php
include_once 'connection.php';

class User {

private $db;
private $connection;

function __construct() {
    $this -> db = new DB_Connection();
    $this -> connection = $this->db->getConnection();
}

public function does_user_exist($name,$tel_no,$contact_point,$email,$address,$logo_url, $operation_time,$encrypted_password)
{
    $query = "Select * from shop where email='$email'  ";
    $result = mysqli_query($this->connection, $query);
    if(mysqli_num_rows($result)>0){
        $json['fail'] = ' Already registered '.$email;
        echo json_encode($json);
        mysqli_close($this -> connection);
    }else{
        $query = "insert into shop (name, tel_no, contact_point, email, address, logo_url, operation_time, password) values ( '$name','$tel_no','$contact_point','$email','$address','$logo_url','$operation_time','$encrypted_password')";
        $inserted = mysqli_query($this -> connection, $query);
        if($inserted == 1 ){
            $json['success'] = 'Account created';
        }else{
            $json['error'] = 'Wrong password';
        }
        echo json_encode($json);
        mysqli_close($this->connection);
    }

}

 }


$user = new User();

 ..........
试试这个

<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "mydb";

$connection = mysqli_connect($servername,$username,$password,$database);

if (!$connection) {
    die("Connection Failed" .mysqli_connect_error());
}
else 
    echo "Connection Sucessful"

//$data = $_POST["data"];
$stat = $connection->prepare("SELECT name, tel_no, contact, email, address, 
logo_url ,operation_time, encrypted_password from mytable");

$stat->execute();

$stat ->bind_result($name, $tell_no, $contact, $email, $address, 
$logo_url ,$operation_time, $encrypted_password);

$data = array();

while ($stat->fetch()) {

    $temp = array();
    $temp['name'] = $name;
    $temp['tel_no'] = $tel_no;
    $temp['contact'] = $contact;
    $temp['email'] = $email;
    $temp['address'] = $address;
    $temp['logo_url'] = $logo_url;
    $temp['operation_time'] = $operation_time;
    $temp['encrypted_password'] = $encrypted_password;


    array_push($data, array("data"=>$temp));
}


echo json_encode($data);


?>


注意:Android Studio是IDE。您没有试图将任何JSON放入其中,也没有试图在其中显示。您正试图将其应用到Android应用程序中。这是一个重要的区别。如果你在记事本上编写PHP代码,你不会说你正在从记事本上获取数据。你看,现在很难确定问题所在,因为你的PHP脚本或Android都可能有问题。因此,我建议您通过POSTMAN测试您的PHP脚本,看看您是否得到了有效的响应(成功或失败)。如果是,请在问题中提供JSON。
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$database = "mydb";

$connection = mysqli_connect($servername,$username,$password,$database);

if (!$connection) {
    die("Connection Failed" .mysqli_connect_error());
}
else 
    echo "Connection Sucessful"

//$data = $_POST["data"];
$stat = $connection->prepare("SELECT name, tel_no, contact, email, address, 
logo_url ,operation_time, encrypted_password from mytable");

$stat->execute();

$stat ->bind_result($name, $tell_no, $contact, $email, $address, 
$logo_url ,$operation_time, $encrypted_password);

$data = array();

while ($stat->fetch()) {

    $temp = array();
    $temp['name'] = $name;
    $temp['tel_no'] = $tel_no;
    $temp['contact'] = $contact;
    $temp['email'] = $email;
    $temp['address'] = $address;
    $temp['logo_url'] = $logo_url;
    $temp['operation_time'] = $operation_time;
    $temp['encrypted_password'] = $encrypted_password;


    array_push($data, array("data"=>$temp));
}


echo json_encode($data);


?>