Send Int in HashMap with Volley

2019-03-03 03:56发布

i have implemented this answer - https://stackoverflow.com/a/19945676/4281848 in my code and it works great, however i am currently trying to send an integer with the hashmap and it is of course saying that it can only send strings, how could i change this to allow sending integers as well as strings

Here is my current code

    HashMap<String, Integer> params = new HashMap<String, Integer>();
                params.put("uid", userId);

                CustomRequest jsObjRequest = new CustomRequest(Request.Method.POST,
                        jsonUrl,params,
                        new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                try {
                                    VolleyLog.v("Response:%n %s", response.toString(4));
                                    int code = response.getInt("code");
                                    String message = response.getString("message");

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.e("Error: ", error.getMessage());
                    }
                });

                AppController.getInstance().addToRequestQueue(jsObjRequest, tag_json_obj);

Thanks for any and all help

1条回答
孤傲高冷的网名
2楼-- · 2019-03-03 04:33

change:

HashMap<String, Integer> params = new HashMap<String, Integer>();
            params.put("uid", userId);

to

HashMap<String, String> params = new HashMap<String, String>();
            params.put("uid", String.valueOf(userId));
查看更多
登录 后发表回答