前端传入多个json字符后端接收

如果前端传入多个json字符串,如:

[{"id":"8a015c6d606d28aa01606dcd480601fd","cancelReason":"12"},{"id":"8a015c6d607cf23701607cfb94a0006b","cancelReason":"test"}]

后台controller接收:

 @PostMapping(value = "/issueCollectRevoke")
    public Result issueCollectRevoke(@RequestBody String revoke)

service层处理通过fastJson:

public void issueCollectRevoke(String revoke) {
        // 返回json的数组
        List list = new ArrayList<>();
        list = JSON.parseArray(revoke, RevokeDto.class);
        List list1 = new ArrayList<>();
        Map map = new HashMap<>();
        for (int i = 0; i < list.size(); i++) {
            String cancelReason = list.get(i).getCancelReason();
            String id = list.get(i).getId();
            list1.add(id);
            map.put(id,cancelReason);
        }

 

你可能感兴趣的:(java后台)