Android POST请求向后台提交json的几种json格式

第一种形式.

{
 "buyerId": "380115f6e5641304eccd59f335734f62",
 "channel": "0001",
 "orderAmount": "10000023",
 "orderNumber": "00120190625140014645007913299",
 "payAmount": "1",
 "totalAmount": "0",
 "orderInfos": [{
  "amount": "10000023",
  "businessId": "00120190625140014645007913299",
  "businessType": "1",
  "commodityId": "",
  "commodityName": "",
  "commodityNum": "",
  "commodityPrice": "",
  "commodityType": "",
  "consumptionType": "1",
  "merno": "3801",
  "remark": "订单明细1"
 }]
}

第一种实现方式:

JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
JSONObject tag = new JSONObject();
tag.put("amount", money);
tag.put("businessType", "2");
tag.put("commodityId", id);
tag.put("commodityName", address);
tag.put("commodityPrice", money);
tag.put("commodityType", "");
tag.put("consumptionType", "");
tag.put("merno", merno);
tag.put("remark", feelname);
jsonArray.add(tag);
jsonObject.put("orderInfos", jsonArray);
jsonObject.put("buyerId", SharedPreferencesUtil.get(context, "userId", ""));
jsonObject.put("orderAmount", money);
jsonObject.put("channel", "0001");
jsonObject.put("payAmount", money);
jsonObject.put("totalAmount", money);
String data = jsonObject.toString();

第二种形式.

{
 "buyerId": "380115f6e5641304eccd59f335734f62",
 "channel": "0001",
 "orderAmount": "10000023",
}

第二种实现方式

HashMap<String, Object> params = new HashMap<>();
params.put("buyerId", "");
params.put("channel", id);
params.put("orderAmount", "");
Gson gson = new Gson();
String strEntity = gson.toJson(map);
Log.e("=====json串", strEntity);

 

第三种形式.

{
 "header": {
  "payKey": "",
  "payWayCode": ""
 },
 "body": {
  "request": {
   "orderNo": "",
   "sign": "",
   "remark": "",
   "trxType": "",
   "payStyle": "",
   "productName": "",
   "deviceInfo": "",
   "orderPeriod": "",
   "orderTime": "",
   "orderIp": "",
   "currency": "",
   "orderPrice": "",
   "returnUrl": "",
   "orderDate": "",
   "merchantNo": ""
  }
 }
}

第三种实现方式

HashMap<String, String> header = new HashMap<>();
header.put("payKey", "");
header.put("payWayCode", "CCBPAY");
final HashMap<String, String> request = new HashMap<>();
request.put("currency", "CNY");
request.put("orderDate", orderDate);
request.put("orderIp", getIPAddress(context));
request.put("orderNo", orderNo);
request.put("orderPeriod", "5");
request.put("orderPrice", money);
request.put("orderTime", orderTime);
request.put("productName", feelname);
request.put("prodCate", feelname);
request.put("producDesc", feelname);
request.put("remark", address);
request.put("returnUrl", "order/callbackByPay");
request.put("merchantNo", merno);
request.put("deviceInfo", tm.getDeviceId());
request.put("trxType", "");
request.put("payStyle", pay);
request.put("sign", "");
HashMap<String, Map> body = new HashMap<>();
body.put("request", request);
HashMap<String, Map> paramsMap = new HashMap<>();
paramsMap.put("body", body);
paramsMap.put("header", header);

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值