java - 将 json 返回格式表示为不同的格式
问题描述
我在休息服务中创建了一个方法并在邮递员中对其进行了测试,它返回了这种格式:
{
"account": [
{
"id": 1,
"password": "a",
"pop3": "pop3",
"smtp": "smtp",
"username": "a"
}
]
}
我的服务方法代码:
@GET
@Path("/accounts")
@Produces(MediaType.APPLICATION_JSON)
public List<Account> getAccounts(){
Account a = new Account();
a.setId(1);
a.setSmtp("smtp");
a.setPop3("pop3");
a.setUsername("a");
a.setPassword("a");
List<Account> accounts = new ArrayList<>();
accounts.add(a);
return accounts;
}
有没有办法以这种格式返回?
[
{
"id": 1,
"password": "a",
"pop3": "pop3",
"smtp": "smtp",
"username": "a"
}
]
解决方案
推荐阅读
- c# - Unity Move() 函数在角色控制器上不起作用
- ios - 如何在集合视图中保存一组图像swift 4
- cookies - 在 HTTP/2 流中有多个“set-cookie”标头是否可以接受?
- matlab - 如何在 MATLAB 中加速非常慢的动画绘图
- c++ - 关于在 C++ 中访问字符串的字母
- c++ - 避免 3+ 整数的整数乘法溢出
- twitter-bootstrap - 带有圆形边框的轮播上的可见图像边缘
- html - ng重复元素内的引导下拉菜单被溢出自动隐藏
- pandas - Pandas:比较大数据框和小数据框
- java - Java:在堆栈帧中,当前常量池引用值何时以及如何填充?