JSON封装数据库查询结果集,为什么只查出一条??
tmDaot=newtmDao();StringweekID=request.getParameter("weekID");ArrayList<timetable>lis...
tmDao t=new tmDao();
String weekID=request.getParameter("weekID");
ArrayList<timetable> list=t.queryMonday(weekID);
JSONArray array=new JSONArray();
JSONObject obj=new JSONObject();
for(int i=0;i<list.size();i++){
timetable tm=list.get(i);
obj.put("节数", tm.getClassID());
obj.put("课程名称", tm.getClassname());
obj.put("上课地点", tm.getPlace());
obj.put("持续周数", tm.getWeek());
obj.put("类型", tm.getType());
obj.put("工作日", tm.getWeekID());
obj.put("上课时间", tm.getTime());
array.add(obj);
}
out.print(array.toString());
out.flush();
out.close();
}
浏览器显示结果:
[{"节数":"1-2节","课程名称":"数据结构","上课地点":"北1303","持续周数":"第1到16周","类型":"","工作日":"星期一","上课时间":"8:30"}] 展开
String weekID=request.getParameter("weekID");
ArrayList<timetable> list=t.queryMonday(weekID);
JSONArray array=new JSONArray();
JSONObject obj=new JSONObject();
for(int i=0;i<list.size();i++){
timetable tm=list.get(i);
obj.put("节数", tm.getClassID());
obj.put("课程名称", tm.getClassname());
obj.put("上课地点", tm.getPlace());
obj.put("持续周数", tm.getWeek());
obj.put("类型", tm.getType());
obj.put("工作日", tm.getWeekID());
obj.put("上课时间", tm.getTime());
array.add(obj);
}
out.print(array.toString());
out.flush();
out.close();
}
浏览器显示结果:
[{"节数":"1-2节","课程名称":"数据结构","上课地点":"北1303","持续周数":"第1到16周","类型":"","工作日":"星期一","上课时间":"8:30"}] 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询