Postman传递Json字符串型数组转List,并存入父类的List属性中

一、Postman传递Json字符串型数组到服务器

1.1选择Body--->raw--->JSON(application/json)

1.2Json数组格式:{"list":[{"plateNo":"京A88888","flag":"1"},{"plateNo":"京A66666","flag":"3"}]}

1.3自定义接收前端传递到后台服务器的参数:reqBO.getList()--->该数值为Json字符串型数组;

二、定义实体类

2.1定义接受Json数组的实体类——***ReqListBO

2.2定义包含***ReqListBO实体类的父类——***ReqBO

三、具体传递及转换方式

3.1

字符串型JSON数组reqBO.getList()--->转换为Json数组对象jsonarray

Array jsonarray = JSONArray.fromObject(reqBO.getList());

3.2

Json数组对象jsonarray--->转换为list集合

List list = (List) JSONArray.toCollection(jsonarray, NotifyOpenVehPlatePayReqListBO.class);

3.3

①迭代list集合--->把list集合,对应放入***ReqListBO实体类对象中

②把***ReqListBO实体类对象,放入***ReqListBOS集合对象中

Iterator it = list.iterator();
List<NotifyOpenVehPlatePayReqListBO> notifyOpenVehPlatePayReqListBOS = new ArrayList<>();
while (it.hasNext()) {
    NotifyOpenVehPlatePayReqListBO notifyOpenVehPlatePayReqListBO = (NotifyOpenVehPlatePayReqListBO) it.next();
    notifyOpenVehPlatePayReqListBOS.add(notifyOpenVehPlatePayReqListBO);
}

3.4

把***ReqListBOS集合对象,放入父类ReqListBO实体类的集合中

reqBO.setNotifyOpenVehPlatePayReqListBO(notifyOpenVehPlatePayReqListBOS);

---------------------------------------------------------------大功告成!

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值