I'm trying to connect my Android app to my Laravel API and I'm receiving the following error.
Value string(2) of type java.lang.String cannot be converted to JSONObject
after running my volley request. The request goes trough, but I cannot check for status of the request because it always returns an error.
I believe it is because I'm returning a JSON Array in my Laravel app.
This is my Laravel's app response on success
return Response::json(array(
'status' => 'ok',
'message' => 'success',
));
And this is my Volley request on Android
RequestQueue queue = Volley.newRequestQueue(this);
Log.d("sendOrderToServer", "called");
Log.d("json obj", order.toString());
JsonObjectRequest jsor = new JsonObjectRequest(MainActivity.ADD_ORDER, order, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("response", response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.d("error34", error.toString());
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("charset", "utf-8");
return headers;
}
};
queue.add(jsor);
How could I do this properly without manually parsing a string and making a string request in Android Volley library?