Struts2+Jquery實現ajax並返回json類型數據

http://www.open-open.com/lib/view/open1371818626400.html
這個是傳多個對象的寫法
if (list != null) {
JSONArray jsonArray = new JSONArray();
for (OrderItem o : list) {
JSONObject obj = new JSONObject();
obj.put(“pic”, o.getProduct().getPic());
obj.put(“name”, o.getProduct().getName());
obj.put(“price”, o.getProduct().getPrice());
obj.put(“amount”, o.getAmount());
jsonArray.add(obj);
}
json = jsonArray.toString();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章