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

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/Mr___Xu/article/details/94594551

第一种形式.

{
 "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);

猜你喜欢

转载自blog.csdn.net/Mr___Xu/article/details/94594551