I am writing a java code in Android Studio to POST to my local webapi. Running through emulator.
public static final String ROOT_URL = "http://10.0.2.2:9998/api/users";
But while POST, below error appears. Even though I am able to POST via postman.
com.android.volley.ParseError: org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject
Here is my code:
RegisterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RequestQueue requestQueue = Volley.newRequestQueue(Registration2.this);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URLs.ROOT_URL, parameters,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("Result of POST :", response.toString());
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("ERRORAS 2 :", error.toString());
}
});
requestQueue.add(jsonObjectRequest);
//Intent intent = new Intent(Registration2.this,LandingPage.class);
//startActivity(intent);
}
});
,,,
This is my JSONObject:
final JSONObject parameters = new JSONObject();
try {
parameters.put("FirstName", "Vedaanth");
parameters.put("LastName", "Pradhan");
parameters.put("PhoneNumber", "9*******1");
parameters.put("EmailID", "p******@gmail.com");
} catch (JSONException e) {
e.printStackTrace();
}
Am i doing anything wrong?
As you are getting a response whose type is number but in your code, you are expecting a JsonObject which is causing the issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.