Android转换集合数据(ArrayList)为Json格式并上传服务器


 

 

    使用Gson上传集合数据到服务器,1.最外层用 ArrayMap<String, Object> 封装;2.通过  mRequestParam.put("cmdLineIds", cmdLineIds);存入集合数据;3.用GSON.toJson转换成标准Json字符串传到服务器上。

 @Override
 public Flowable<String> uploadCollectionData(String businessType, List<CmdLineId> cmdLineIds) {
     // ArrayMap<String, Object> mRequestParam;
     mRequestParam.clear();
     mRequestParam.put("businessType", businessType);
     mRequestParam.put("cmdLineIds", cmdLineIds);
     Log.v("yff", "up: " + JsonUtil.map2Json(mRequestParam));//  new Gson().toJson(map); return mRequestApi.uploadCollectionData(JsonUtil.map2Json(mRequestParam)).compose(TransformerHelper.MapTransformer);
 }

Log:

{
    "cmdLineIds": [
        {
            "cmdLineId": "20180823002001"
        },
        {
            "cmdLineId": "201808280041"
        }
    ],
    "businessType": "E4"
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM