gmc1103 Posted June 12, 2015 Share Posted June 12, 2015 Hi again Another issue. This is my php code if ($tag == 'reqSalasCheck') { $sala = filter_input(INPUT_POST, 'sala'); $inicio = filter_input(INPUT_POST, 'inicio'); $fim = filter_input(INPUT_POST, 'fim'); $data = filter_input(INPUT_POST, 'dataFinal'); $dias = strftime('%A', strtotime($data)); $newDate = date("Y-m-d", strtotime($data)); $diaId = mysql_query("SELECT * FROM `ebspma_paad_ebspma`.`semana_dias` WHERE dia ='$dias'"); $diaRow = mysql_fetch_row($diaId)or die(mysql_error()); $Dias = $diaRow[0]; if ($Dias != null) { $inicioId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `inicio`='$inicio'"); $inicioRow = mysql_fetch_row($inicioId)or die(mysql_error()); $inicio = $inicioRow[0]; if ($inicio != null) { $salaId = mysql_query("SELECT `idsala` FROM `ebspma_paad_ebspma`.`req_material_sala` WHERE `sala` = '$sala'"); $salaRow = mysql_fetch_row($salaId)or die(mysql_error()); $sala = $salaRow[0]; if ($sala != null) { $fimId = mysql_query("SELECT `idtempo` FROM `ebspma_paad_ebspma`.`req_material_tempo` WHERE `fim`= '$fim'"); $fimRow = mysql_fetch_row($fimId)or die(mysql_error()); if ($fim != null) { $checkIfOcupado = mysql_query("SELECT COUNT(id_dia) FROM `ebspma_paad_ebspma`. `sala_ocupacao` WHERE id_dia = '$Dias' AND id_sala= '$sala' AND id_tempo = '$inicio'"); $checkResult = mysql_fetch_row($checkIfOcupado) or die($checkIfOcupado . "<br/><br/>" . mysql_error()); $checkResultado = $checkResult[0]; if ($checkResultado > 0) { $response["error"] = 2; $response["error_msg"] = "Hora marcada no ano"; echo json_encode($response); } else { $checkIfReservado = mysql_query("SELECT COUNT(*) AS total FROM `ebspma_paad_ebspma`.`req_material_reserva` WHERE `ebspma_paad_ebspma`.`req_material_reserva`.`idsala` = '$sala' AND (((`req_material_reserva`.`idtempoInicio` BETWEEN '$inicio' AND '$fim') AND (`req_material_reserva`.`idTempoFim` BETWEEN '$inicio' AND '$fim')) OR (`req_material_reserva`.`idtempoInicio` <= '$inicio' AND `req_material_reserva`.`idTempoFim` >= '$fim')) AND `req_material_reserva`.`data` = '$newDate'"); $checkReserva = mysql_fetch_row($checkIfReservado) or die($checkIfReservado . "<br/><br/>" . mysql_error()); $checkReservado = $checkReserva[0]; if ($checkReservado > 0) { $response["error"] = 2; $response["error_msg"] = "Oops! Sala reservada"; echo json_encode($response); } else { $response["success"] = 1; $response["message"] = "Sala disponível."; echo json_encode($response); } } } } } } } And have this error in my android Error parsing data org.json.JSONException: End of input at character 0 of org.json.JSONException: No value for message And my android is calling this json private static final String KEY_MESSAGE = "message"; private static final String KEY_MESSAGE_ERROR = "error_msg"; JSONObject salasCheck = userFunctions.reqSalasCheck(sala, inicio, fim, dataReserva); try { String res = salasCheck.getString(KEY_SUCCESS); Log.d("Mensagem", res); String error = salasCheck.getString(KEY_ERROR); Log.d("Mensagem", error); if (Integer.parseInt(res) == 1) { String messageOK = salasCheck.getString(KEY_MESSAGE); So why do i have this error in my php?? Quote Link to comment https://forums.phpfreaks.com/topic/296776-jsonexception-no-value-for-message/ Share on other sites More sharing options...
QuickOldCar Posted June 12, 2015 Share Posted June 12, 2015 Check to see if actually getting a response then check if it's valid. http://jsonlint.com/ Quote Link to comment https://forums.phpfreaks.com/topic/296776-jsonexception-no-value-for-message/#findComment-1513740 Share on other sites More sharing options...
gmc1103 Posted June 12, 2015 Author Share Posted June 12, 2015 Hi I don't get what's wrong in this code...everything is so strange. I'm passing the variables to php from this code @SuppressLint("SimpleDateFormat") public JSONObject reqSalasCheck(String sala, String inicio, String fim, Date dataReserva) { // Parametros a passar para php List<NameValuePair> params = new ArrayList<NameValuePair>(); String dataFinal = String.valueOf(dataReserva); String reqSalasCheck_tag = "reqSalasCheck"; params.add(new BasicNameValuePair("tag", reqSalasCheck_tag)); params.add(new BasicNameValuePair("sala", sala)); params.add(new BasicNameValuePair("inicio", inicio)); params.add(new BasicNameValuePair("fim", fim)); params.add(new BasicNameValuePair("dataFinal", dataFinal)); JSONObject json = jsonParser.getJSONFromUrl(loginURL, params); return json; } and the debuger gives me this error Method threw 'java.lang.NullPointerException' exception. Cannot evaluate org.apache.http.message.BasicNameValuePair.toString() in every variable Quote Link to comment https://forums.phpfreaks.com/topic/296776-jsonexception-no-value-for-message/#findComment-1513743 Share on other sites More sharing options...
kirk7 Posted September 11, 2017 Share Posted September 11, 2017 (edited) Use this to validate your JSON: json formatter Edited September 11, 2017 by kirk7 Quote Link to comment https://forums.phpfreaks.com/topic/296776-jsonexception-no-value-for-message/#findComment-1551120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.