struts2 的 json 格式化

 

普通属性 格式化成键值对。map 格式化成单个对象,list 格式化成对象数组。

  • int totalCount=100;

    格式化成 "totalCount":100

  •  Map total = new  HashMap();

     total.put("totalCount", 100);

     格式化成 "total":{"totalCount":100}

  • List topic = new ArrayList();
    格式化成 "topics":[{"author":"author0","lastpost":"last0“},":[{"author":"author0","lastpost":"last0“}]

 多个属性可以格式化到一个json 对象中 {topic:[],totalCount:100}

JSON 注释

@JSON

name: 设置成JSON对象的属性名

serialize 是否序列化该属性
deserialize:设置是否反序列化该属性。
format:设置用于格式化输出、解析日期表单域的格式。例如"yyyy-MM-dd'T'HH:mm:ss"。

相关文章:

  • 2022-01-24
  • 2021-12-11
  • 2021-10-28
  • 2022-12-23
  • 2021-08-05
  • 2021-09-24
  • 2021-09-17
猜你喜欢
  • 2022-12-23
  • 2021-07-26
  • 2022-12-23
  • 2021-09-29
相关资源
相似解决方案