Map cart=(Map)session.getAttribute("cart");
//如果没有购物车,则创建一个
if(cart==null){
cart=new HashMap();
session.setAttribute("cart", cart);
}
//在购物车中遍历将要添加的商品,如果已经存在,则数量+1,
//否则设置数量为1,存入购物车
CartModel coursecars=cart.get(trainwishid);
if(coursecars!=null){
coursecars.setCount(coursecars.getCount()+1);
}else{
// CourseModel stor=service.findAllForCart(Integer.parseInt(id));
CartModel c=new CartModel();
c.setCount(1);
c.setCourseCode(trainwishid);
cart.put(trainwishid, c);
session.setAttribute("cart", cart);
}
System.out.println(JSONArray.fromObject(cart).toString());
out.println(JSONArray.fromObject(cart).toString());
out.close();
得到的数据是这种,要怎么解析??????
[{"123451234":{"count":1,"courseCode":"123451234"},"47867989 8":{"count":1,"courseCode":"47867989 8"}}]