有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

通用域名格式。安卓截击解析错误:org。json。JSONException:类型为java的值0。lang.Integer无法转换为JSONObject

我正在Android Studio中编写java代码,以发布到我的本地webapi。通过模拟器运行

public static final String ROOT_URL = "http://10.0.2.2:9998/api/users";

但在发布时,会出现以下错误。即使我可以通过邮递员邮寄

com.安卓.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();
    }

我做错什么了吗


共 (1) 个答案

  1. # 1 楼答案

    当您得到一个类型为number但在代码中的响应时,您希望得到一个引起问题的JsonObject