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