【问题标题】:Send Int in HashMap with Volley使用 Volley 在 HashMap 中发送 Int
【发布时间】:2014-12-14 01:54:23
【问题描述】:

我已经实现了这个答案 - https://stackoverflow.com/a/19945676/4281848 在我的代码中并且效果很好,但是我目前正在尝试使用哈希图发送一个整数,当然它只能发送字符串,我该如何更改它以允许发送整数和字符串

这是我当前的代码

    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);

感谢大家的帮助

【问题讨论】:

  • 为什么需要这样做?最后所有的参数都会转成String,完全没必要。

标签: android android-volley


【解决方案1】:

改变:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2018-02-16
    • 2013-08-05
    相关资源
    最近更新 更多