VolleyPost请求,数组形式的参数有的手机提交不了

VolleyPost请求,数组形式的参数有的手机提交不了,试了好多次,才发现可能数组传的有问题,先贴错误代码:

        HashMap<String, Object> params = new HashMap<>();
        params.put("name", mAddBrandName);
        if (categoryIds != null) {
            params.put("categoryIds", categoryIds);
        }
        for (int i = 0; i < categoryIds.length; i++) {
            System.out.println(categoryIds[i]);
        }
        JSONObject json = new JSONObject(params);
        VolleyRequest.jsonRequest(this, Request.Method.POST, Constant.Brand_Save, Constant.HGJ_TAG, json, new VolleyInterface(this, VolleyInterface.mListener, VolleyInterface.mErrorListener) {
            @Override
            public void onMySuccess(JSONObject result) {
             
                if (result != null) {
                    try {
                        if (result.getInt("code") == 200) {
                            CommonUtils.showToastMsg(AddNewBrandActivity.this, "添加成功");
                            finish();
                        } else {
                            CommonUtils.showToastMsg(AddNewBrandActivity.this, result.getString("msg"));
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            @Override
            public void onMyError(VolleyError error) {
                CommonUtils.showToastMsg(AddNewBrandActivity.this, "请求失败");
            }
        });
 
此次提交的数据参数中,categoryIds是一个数组,我在魅族手机,小米手机,三星手机中可以提交成功,但谷歌模拟器,OPPO等手机就请求失败。这次换了JSON解析的方法,这次成功了。代码如下:

        HashMap<String, Object> params = new HashMap<>();
        params.put("name", mAddBrandName);
        if (categoryIds != null) {
            params.put("categoryIds", categoryIds);
        }
        for (int i = 0; i < categoryIds.length; i++) {
            System.out.println(categoryIds[i]);
        }
//        {"name":"好利来","categoryIds":[2,3]}
        String strJson = GsonUtils.parseMapToJson(params);
        JSONObject json = null;
        try {
            json = new JSONObject(strJson);
        } catch (JSONException e) {
            e.printStackTrace();
        }
 
剩余代码都一样哦.

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值