public void searchLoginInfo(View view) {
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, showUrl,null,new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray users = response.getJSONArray("users");
for (int i = 0; i < users.length(); i++){
JSONObject user = users.getJSONObject(i);
String username = user.getString("username").toLowerCase();
String password = user.getString("password".toLowerCase());
String retypedpassword = user.getString("retypedpassword");
String email = user.getString("email");
if (username.equals(myLoginList.get(0)) && password.equals(myLoginList.get(1))) {
Toast.makeText(LoginActivity.this, "Login Succesfull", Toast.LENGTH_LONG).show();
Intent send = new Intent(LoginActivity.this, WelcomeActivity.class);
startActivity(send);
break;
}else{
Toast.makeText(LoginActivity.this, "Login Failed!", Toast.LENGTH_LONG).show();
Intent send = new Intent(LoginActivity.this, LoginActivity.class);
startActivity(send);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volley Error", error.toString());
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null) {
Log.e("Status code", String.valueOf(networkResponse.statusCode));
}
}
});
requestQueue.add(jsonObjectRequest);
}
I am using a JSON object request to get information from a database that I have created. I am able with my android application to insert data into the database but now I want to check for example if the user created an user account. Both the url and the php files work fine. I have used a log in the onErrorResponse method to see what is the actual error and I got this: E/Volley Error: com.android.volley.ParseError: org.json.JSONException: Value Connection of type java.lang.String cannot be converted to JSONObject. I do not know what seems to be the problem with this. I have also checked using postamn if my web service is returning json data.Printscreen with the json data Can anybody help me? Thanks in advance
Log.debugthe data so you can see what you're actually working with. If you ever don't understand why something is behaving in a particular way, look at it in smaller pieces. :)