在 SessionBean 中接收查询结果
public List getUserTransaction(User user, Balancestatus status) {
return em.createNamedQuery("Balance.findLastFiveTransaction").setParameter("user", user).setParameter("status", status).getResultList();
我的查询
select b from Balance b join b.typecategory t where b.user = :user and b.typecategory = t and b.status = :status
在 servlet 中获取数据并传递给 Json
PrintWriter out = response.getWriter();
user = userHandler.userCheck("mail@mail.com");
List<Balance> userTransaction = balance.getUserTransaction(user, outStatus);
Gson gson = new Gson();
String json = gson.toJson(userTransaction);
out.write(json);
尝试使用 JQuery 解析并在控制台中输出
.............
$.each(data, function(index, element) {
console.log(element);
});
..............
并得到错误
TypeError:无效的'in'操作数obj [中断此错误]
typeof length === "number" && length > 0 && (length - 1) in obj );
我的 Json 从 ArrayList 到 Json
[{"id":"7","description":"邪恶数据展示","sum":666.00,"category":{"id":"1","name":"Wallet"},"typecategory ":{"id":"4","name":"Home"},"user":{"id":"1","created":"2013 年 6 月 5 日下午 1:44:45", "email":"mail@mail.com","pass":"mail","updated":"2013 年 6 月 5 日下午 1:44:45"},"status":{"id":"2" ,"statusName":"out"}} .........]
如何正确地将 ArrayList 传递给 Json?使用 JBoss AS 7.1