0
我开始使用json,需要一些帮助来解决这个问题。Gson名称数组,并包含一个新属性
我有一个POJO
public class HiReceiptsObj{
private string warehouse_id;
private String owner_id;
private String receipt;
.....// all with Getters and setters
}
我调用Java方法,其中我加载收据的ArrayList像这样
List<HiReceiptsObj> receipts = new ArrayList<HiReceiptsObj>();
,然后我用GSON到ArrayList转换为JSON
String receiptsJson = new Gson().toJson(receipts);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(receiptsJson);
This will output
[{"warehouse_id":"US01","owner_id":"NP ","receipt":"INV"},
{"warehouse_id":"US01","owner_id":"NP ","receipt":"082212-3047 "},
{"warehouse_id":"US01","owner_id":"NP ","receipt":"INVADJUST"}]
我需要这种输出的
{
"total_pages": 10,
"rows": [
{"warehouse_id":"US01","owner_id":"NP ","receipt":"INV"},
{"warehouse_id":"US01","owner_id":"NP ","receipt":"082212-3047 "},
{"warehouse_id":"US01","owner_id":"NP ","receipt":"INVADJUST"}
]
}
我已阅读有关本的其他职位,但他们对我来说太先进了,可有人请帮助?
感谢
你先生是棒极了.. – user2797021 2014-10-28 16:07:49