Undefined index JSON Android

0

Hello, I have the following error: I am developing an application that checks a table from an external mysql database by sending the device IMEI returning an equipment id, but debugging the code in the AsyncHttpResponseHandler response line shows the following message (copied and pasted creating an html file). I would like to know what I am doing wrong in my code

MethodthatsendstheIMEItosearch

publicvoidsendIMEIgetEquip(){TelephonyManagertelephonyManager=(TelephonyManager)this.getSystemService(TELEPHONY_SERVICE);StringIMEI=telephonyManager.getDeviceId();JSONObjectjson=newJSONObject();Stringpath;try{json.put("imei", IMEI);
        json.put("idEquip", 0);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    AsyncHttpClient client = new AsyncHttpClient();
    RequestParams params = new RequestParams();
    params.put("imei",json);
    path = "http://"+ip+"/mytolite/equipamento/getequipbyimei.php";
    client.get(path, params, new AsyncHttpResponseHandler() {
        @Override
        public void onSuccess(String response) {
            setMyEquip(response);
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
            dialog.hide();
            if (statusCode == 404) {
                Toast.makeText(getApplicationContext(), "Recurso requisitado não encontrado", Toast.LENGTH_SHORT).show();
            } else if (statusCode == 500) {
                Toast.makeText(getApplicationContext(), "Erro de servidor", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(getApplicationContext(), "Erro inesperado [verifique sua conexão]", Toast.LENGTH_LONG).show();
            }
        }
    });
}

php code that handles json

<?php
/**
 * Updates Sync status of Users
 */
include_once './db_functions.php';
//Create Object for DB_Functions clas
$db = new DB_Functions();
//Get JSON posted by Android Application
$json = $_POST["imei"];
//Remove Slashes
echo $json;
if (get_magic_quotes_gpc()){
$json = stripslashes($json);
}
//Decode JSON into an Array
$data = json_decode($json);
//Util arrays to create response JSON
$a=array();
$b=array();
//Loop through an Array and insert data read from JSON into MySQL DB

//Store User into MySQL DB
$equip = $db->getEquipByImei($data->imei);
//Based on inserttion, create JSON response
    while ($row = mysqli_fetch_array($equip)) {
        $b["id"] = $row["id"];
        array_push($a,$b);
    }
    try{
        if($a == ''){
            echo 'jsonvazio';
        }else {
            echo json_encode($a);
        }
    }catch (Exception $e){
        echo json_last_error_msg();
        echo 'exceção: ', $e->getMessage(), "/n";
    }
?>

php method that returns the device id based on the device's IMEI

    public function getEquipByImei($imei){
    $result = mysqli_query($this->db->connect(), "SELECT idEquipamento FROM equipamentotablet WHERE imei = '$imei'");
    return $result;
}

Note: Line 9: $ json = $ _POST ["imei"]; (I believe it is here that he is not finding the json index) Line 23: $ equip = $ db- > getEquipByImei ($ data- > imei);

Thanks for the help right away.

    
asked by anonymous 14.10.2015 / 19:36

1 answer

0

Good afternoon, try to use instead of $_POST $_REQUEST , and in HTTP of android try to use client.post(...) .

    
14.10.2015 / 20:10