Struts2 返回的json如下:
{"category":[{"id":"66bca886-3ddb-4df4-b393-d8d4788974c9","parentId":"0","title":"新闻"},{"id":"93013fb0-5d39-41c5-9891-7832d324a3a9","parentId":"0","title":"新闻222"},{"id":"ae84377b-7f6e-46ac-b9e8-12ffbffb83e9","parentId":"0","title":"新闻1111"}]}
:
返回之前是LIST里面放了Category对象。但是返回后的这个json对象中我不要category ,我直接要生成如下的效果:
[{"id":"66bca886-3ddb-4df4-b393-d8d4788974c9","parentId":"0","title":"新闻"},{"id":"93013fb0-5d39-41c5-9891-7832d324a3a9","parentId":"0","title":"新闻222"},{"id":"ae84377b-7f6e-46ac-b9e8-12ffbffb83e9","parentId":"0","title":"新闻1111"}]
这样要怎么设置啊。
直接使用Gson,将放有Category对象的List转换成Json字符串
Gson gson = new Gson(); String jsonString = Gson.toJson(categoryList);