包括Gson的顶级元素(Including a top level element with Gson)
我有这样的POJO
public class Pojo { ... public static String toJson(ArrayList<Pojo> pojos) { Gson gson = new Gson(); return gson.toJson(pojos); } }
输出是:
[ { "arrival": "19:12:30", "typeOfDay": "regular", "stopCode": "CMPZ", "route": "B", "id": 1 }, { "arrival": "19:13:30", "typeOfDay": "regular", "stopCode": "AVSV", "route": "B", "id": 2 } ]
但我想要的是这个:
{ "pojos": [ { "arrival": "19:12:30", "typeOfDay": "regular", "stopCode": "CMPZ", "route": "B", "id": 1 }, { "arrival": "19:13:30", "typeOfDay": "regular", "stopCode": "AVSV", "route": "B", "id": 2 } ] }
我怎么能这样做? 我正在使用Gson 2.2.4
I have a POJO like this
public class Pojo { ... public static String toJson(ArrayList<Pojo> pojos) { Gson gson = new Gson(); return gson.toJson(pojos); } }
The output is:
[ { "arrival": "19:12:30", "typeOfDay": "regular", "stopCode": "CMPZ", "route": "B", "id": 1 }, { "arrival": "19:13:30", "typeOfDay": "regular", "stopCode": "AVSV", "route": "B", "id": 2 } ]
But what I want is this:
{ "pojos": [ { "arrival": "19:12:30", "typeOfDay": "regular", "stopCode": "CMPZ", "route": "B", "id": 1 }, { "arrival": "19:13:30", "typeOfDay": "regular", "stopCode": "AVSV", "route": "B", "id": 2 } ] }
How I can do it? I'm using Gson 2.2.4
原文:https://stackoverflow.com/questions/20530892
更新时间:2024-02-23 18:02
最满意答案
菜单结束时会触发“关闭”事件,因此您不需要额外的超时。 看看这个例子,它有点简单: http : //mmenu.frebsite.nl/mmenu/demo/onepage.html
The "closed" event is triggered when the menu finished closing, so you shouldn't need an extra timeout. Have a look at this example, it's a bit more straightforward: http://mmenu.frebsite.nl/mmenu/demo/onepage.html
相关问答
更多-
这是由于broadscreen.css中的一个错误。 如果添加“overflow-y:auto”,应该修复 在“.mm-menu”选择器中(在第50行)。 This is due to a bug in the widescreen.css. Should be fixed if you add "overflow-y: auto;" in the ".mm-menu" selector (on line 50).
-
-
终于找到了解决方案,只是另一个自定义脚本,它没有产生错误,但与mmenu冲突... Finally found the solution, was just an other custom script which did not produce errors but was in conflict with mmenu...
-
将external ID或任何你喜欢的ID添加到你的外部锚点。 还要在构成“80%werken”菜单的ul添加一个id。 (在这个例子中我使用了80_sub )。 现在将以下内容添加到您的js脚本中: $('#external').click(function(ev) { ev.preventDefault(); //Avoid mmenu to get the click and close var api = $("#my-menu").data( "mmenu" ); a ...
-
代替 删除此文件的第69行中的z-index:1“CSS / jquery.mmenu.all.css” 在主css文件中将z-index设置为auto .mm-slideout { z-index:auto;} instead Remove z-index:1 in row 69 of this file "CSS/jquery.mmenu.all.css" set z-index in your main css file to auto .mm-slideout { z-index:auto;}
-
你确定你至少使用jQuery 1.7吗? 来自jquery.mmenu.js : * @requires jQuery 1.7.0或更高版本 Are you sure you use at least jQuery 1.7? From jquery.mmenu.js: * @requires jQuery 1.7.0 or later
-
mmenu没有关闭锚标签(mmenu not closing on anchor tags)[2023-03-06]
首先,我会删除那些页面锚点中的index.html。 所以;- How it Works
- Affiliated Businesses
也许mmenu已经针对onpage链接进行了更新,但是当我最近更新时,“开箱即用”意味着使用此代码(它在一个演示代码示例中 - onepage.html) var $menu = $('nav#menu'), $html = ... -
在您的正文代码中,使用div标签而不是nav 。 如下所示In your body code, use div tag instead of nav. As g ...
-
jquery mmenu默认打开(jquery mmenu opens by default)[2022-06-29]
将其添加到您的css样式表并测试它: #my-menu:not(.mm-menu) { display: none; } Add this to your css stylesheet and test it: #my-menu:not(.mm-menu) { display: none; } -
菜单结束时会触发“关闭”事件,因此您不需要额外的超时。 看看这个例子,它有点简单: http : //mmenu.frebsite.nl/mmenu/demo/onepage.html The "closed" event is triggered when the menu finished closing, so you shouldn't need an extra timeout. Have a look at this example, it's a bit more straightforwar ...