I have a situation where I use the Android-volleyto POSTmy json object , I was able to successfully publish all the contents, and my data is visible on the server, but the server responds like Stringno way json, this is the reason I get the error.
com.android.volley.ParseError: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
So can volley parse strings when we pass json objects? My working code is below,
HashMap<String, String> params = new HashMap<String, String>();
params.put("email", "dude@gmail.com");
params.put("password", "qweffrty");
params.put("name", "Dudeb");
params.put("place", "Bangalore");
params.put("phone", "991000000000");
JsonObjectRequest request = new JsonObjectRequest(
Request.Method.POST,
Constants.BASE_URL+"register",
new JSONObject(params),
createSuccessListener(),
createErrorListener());
private static Response.Listener<JSONObject> createSuccessListener() {
return new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
String test;
test = "yyy";
}
};
}
private static Response.ErrorListener createErrorListener() {
return new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
String test;
test = "yyy";
}
};
}
source
share