VolleyPost请求,数组形式的参数有的手机提交不了
2015-12-28 13:54
375 查看
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(); }剩余代码都一样哦.
相关文章推荐
- Linux Mysql root 远程访问权限修改 默认字符集修改:
- server.xml和resfile.properties配置实现图片查询
- CocoaPods的安装及使用/利用开源库Diplomat实现分享及第三方登录/git的使用
- Objective-C Runtime 运行时之二:成员变量与属性
- 指向结构体的指针
- Linux常用系统信息查看命令
- 隐式意图跨程序启动
- 微信JS SDK demo 实例
- ios opensource YiYuanGou
- Linux快捷键
- FZU 2221—— RunningMan——————【线性规划】
- OC语言--基础语法
- FZU 1076 穿越沙漠(水~)
- 2015.12杭电校赛 1008 Study Words
- nodeJs学习
- Android开发艺术探索学习笔记(一)
- 【备战面试之】三、依赖注入是什么?
- 告诉你程序员为什么要关注 JavaScript ?
- zzulioj--1712--神秘的数列(水题)
- MySQL运行状态show status中文详解