简体   繁体   English

已嵌套 JSON 的 POST 请求正文

[英]POST request body which has nested JSON

I am succefully able to sent "sticky_agent": [ { "enable": true, "time": "5d" } ], in my request body but I need to send it like this "sticky_agent": { "enable": true, "time": "5d" },我可以在我的请求正文中成功发送“sticky_agent”:[ {“enable”:true,“time”:“5d”}],但我需要像这样发送它“sticky_agent”:{“enable”:true , "时间": "5d" },

List<Sticky_agent> stickyList = new ArrayList<>(); List<Sticky_agent> stickyList = new ArrayList<>(); stickyList.add(new Sticky_agent(true, "5d")); stickyList.add(new Sticky_agent(true, "5d"));

what changes I should make here我应该在这里做些什么改变

key: [{key:value, key:value}]键:[{键:值,键:值}]

The Square brackets [] sometimes means the array or list, and the element is the content wrapped in the Curly bracket {}.方括号 [] 有时表示数组或列表,元素是大括号 {} 中包裹的内容。

If you want to remove the [], just define the attribute as a struct not an array or list.如果要删除 [],只需将属性定义为结构而不是数组或列表。 eg:例如:

public class Demo {

     private StickyAgent stickyAgent;

     public String toJsonString(){
        return new Gson().toJson(this);
     }

    @Data
    public class StickyAgent {
        private boolean enable;
        private String time;
    }
}
 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM