Строка исключений JSON не может быть преобразована в JSONObject.

Я делаю приложение на Android, и я хочу общаться с файлами php. Я могу общаться, но я не могу получить идентификатор пользователя и передать его на Android. Строка исключений JSON не может быть преобразована в JSONObject, которая появляется в Toast, когда я вхожу в действие в Android Studio. Пожалуйста, помогите мне. Я все пробовал.

private static final String URL = "http://192.168.1.43/Teste/list.php"; private AbsListView listView; private String jsonResult; View myView; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { myView = inflater.inflate(R.layout.activity_personal_information,container,false); listView = (AbsListView) myView.findViewById(R.id.listView); accessWebService(); return myView; } ..... try { JSONObject jsonResponse = new JSONObject(jsonResult); JSONArray jsonMainNode = jsonResponse.optJSONArray("Custos"); for (int i = 0; i < jsonMainNode.length(); i++) { JSONObject jsonChildNode = jsonMainNode.getJSONObject(i); String number = jsonChildNode.optString("custos"); String outPut = number + "€"; employeeList.add(createEmployee("custos", outPut)); } } catch (JSONException e) { Toast.makeText(getActivity(), "Error" + e.toString(), Toast.LENGTH_SHORT).show(); } SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), employeeList, android.R.layout.simple_list_item_1, new String[] { "custos" }, new int[] { android.R.id.text1 }); listView.setAdapter(simpleAdapter); } 

Это мой php-файл, где я делаю свой Login (Login.php)

 <?php if($_SERVER['REQUEST_METHOD']=='POST'){ //Getting values $email = $_POST['email']; $password = $_POST['password']; $sql = "SELECT * FROM Utilizadores WHERE email='$email' AND password='$password'"; require_once('connection.php'); $sql = mysqli_query($con,$sql); $check = mysqli_fetch_array($sql,MYSQLI_BOTH); //if we got some result if(isset($check)){ session_start(); $_SESSION['user_id'] = $check['user_id']; //here is where I save the user ID echo "user_id"; }else{ //displaying failure echo "failure"; } 

Это мой java-файл, где я получаю login.php

  public static final String LOGIN_URL = "http://192.168.1.43/user/login.php"; //Keys for email and password as defined in our $_POST['key'] in login.php public static final String KEY_EMAIL = "email"; public static final String KEY_PASSWORD = "password"; //If server response is equal to this that means login is successful public static final String LOGIN_SUCCESS = "user_id"; //*Im using sharedpreferences in Android to mantain session, and I put the user_id here* //Keys for Sharedpreferences //This would be the name of our shared preferences public static final String SHARED_PREF_NAME = "myloginapp"; //This would be used to store the email of current logged in user public static final String EMAIL_SHARED_PREF = "email"; //We will use this to store the boolean in sharedpreference to track user is loggedin or not public static final String LOGGEDIN_SHARED_PREF = "loggedin"; } mysqli_close($con); } 

Это мой php-файл, где я делаю запрос (list.php)

 <?php $host="localhost"; $username="root"; $password=""; $db_name="Parking"; session_start(); $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "select * from Costs where user_id = ". $_SESSION['user_id']; //Here is where I do the query in order to only have the costs of the logged in user... $result = mysql_query($sql); $json = array(); if(mysql_num_rows($result)){ while($row=mysql_fetch_assoc($result)){ $json['Costs'][]=$row; } } mysql_close($con); echo json_encode($json); ?> в <?php $host="localhost"; $username="root"; $password=""; $db_name="Parking"; session_start(); $con=mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql = "select * from Costs where user_id = ". $_SESSION['user_id']; //Here is where I do the query in order to only have the costs of the logged in user... $result = mysql_query($sql); $json = array(); if(mysql_num_rows($result)){ while($row=mysql_fetch_assoc($result)){ $json['Costs'][]=$row; } } mysql_close($con); echo json_encode($json); ?>