码迷,mamicode.com
首页 > 其他好文 > 详细

postman的测试,用对象接收所有的字符串

时间:2019-12-04 19:50:13      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:nal   date   class   ica   esc   ppi   post请求   catch   use   

1.post请求 Headers: Content-Type  application/json

{
  "taskId":"1000001161",
  "createUser":"siwenhu",
  "data":"{\"dataList\":[{\"productDesc\":\"接入\",\"createUser\":\"siwenhu|jackchen\",\"serviceId\":\"12300211\",\"sysName\":\"WMKT-RULE\",\"type\":\"1\",\"subsystem_id\":\"1157\",\"filter\":\"DX01|FY02\",\"productCd\":\"A1110000\"}]}",
  "createDate":"2019-12-04 11:37:09",
  "externalId":"11037540",
  "flowId":"10014002"

}

2.后台对象接收

PostMapping("/wen")
@ResponseBody
public String testJson(@RequestBody Message message){

  JSONObject data_json = null;

  JSONArray data_json_array = null;
  try {
    data_json = new JSONObject(message.getData());
    data_json_array = data_json.getJSONArray("dataList");
  } catch (Exception e) {

  }
  System.out.println(data_json_array.length());
  try {
    System.out.println(data_json_array.get(0).toString());
  } catch (JSONException e) {
    e.printStackTrace();
  }
  return message+"";


}

3.javabean的设置

public class Message {
  private String externalId;
  private String createUser;
  private String data;
  private String createDate;
  private String flowId;
  private String taskId;

}

postman的测试,用对象接收所有的字符串

标签:nal   date   class   ica   esc   ppi   post请求   catch   use   

原文地址:https://www.cnblogs.com/liuyi13535496566/p/11984798.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!