0
Android code:
String caminho = "http://10.0.2.2/system/pages/login";
                HttpURLConnection conn = null;
                BufferedReader reader = null;
                try{
                    URL urlConection = new URL(caminho);
                    conn = (HttpURLConnection) urlConection.openConnection();
                    conn.setDoOutput(true);
                    conn.setRequestMethod("POST");
                    PrintStream ps = new PrintStream(conn.getOutputStream());
                    ps.printf("json", obj.toString());
                    conn.connect();
Code Cakephp:
    public function login(){
    $this->layout = "ajax";
    $dados = json_decode($_REQUEST["json"], true); 
    $ra = $dados["RA"];
    $senha = $dados["Pass"];
    $usuario = array();
    $usuario = $this->User->find("first", ["conditions" => ["User.RA" => $ra, "User.password" => $senha ] ]);
    $retorno = 0;
    if($usuario != null || $usuario != ""){
        $retorno = 1;
    }
    $data = [];
    $data = $usuario["User"];
    echo json_encode(array("dados" => $data));
}
How php returns the array:
{"dados":{"id":"1","status_id":"1","name":"Felipe ","RA":"12342017","email":"[email protected]","password":"123456","data_cancel":null}}
What is the question? I suggest that, in addition to the code, you add more details to your question by clicking edit.
– Wallace Maxters
Hello Wallace. I’m having problems in how to get this array sent by Json on android. The error on android is described as: <pre cannot be converted to Jasonarray. I just don’t understand why this occurs.
– Felipe
So, you’re not sending an array, you’re sending an object with an object inside. Here’s the problem, I suggest you take a look at JSON, to understand better.
– Shogogan