[英]com.android.volley.parseerror org.json.jsonexception value yes of type java.lang.String cannot be converted to JSONObject
[英]com.android.volley.ParseError: org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject
我正在 Android Studio 中编写 java 代码以发布到我的本地 webapi。 通过模拟器运行。
public static final String ROOT_URL = "http://10.0.2.2:9998/api/users";
但是在 POST 时,会出现以下错误。 即使我能够通过 postman 发布。
com.android.volley.ParseError: org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject
这是我的代码:
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);
}
});
,,,
这是我的 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();
}
我做错什么了吗?
当您收到类型为数字但在您的代码中的响应时,您期待一个导致问题的 JsonObject。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.