Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何编辑json列表?_Java_Jquery_Json - Fatal编程技术网

Java 如何编辑json列表?

Java 如何编辑json列表?,java,jquery,json,Java,Jquery,Json,我有一个列表,我把这个列表放在json对象中,我想用jquery迭代这个列表,我需要附加到表中。有人能帮我解决这个问题吗 这是我的动作课 String startdate = request.getParameter("startdate"); String endate = request.getParameter("endate"); String leavepolicyid = request.getParameter("leavepolicyid"); S

我有一个列表,我把这个列表放在json对象中,我想用jquery迭代这个列表,我需要附加到表中。有人能帮我解决这个问题吗

这是我的动作课

    String startdate = request.getParameter("startdate");
    String endate = request.getParameter("endate");
    String leavepolicyid = request.getParameter("leavepolicyid");
    Session session = HibernateUtil.getSessionFactory().openSession();
    LeavePolicyEntity lpe = (LeavePolicyEntity) session.get(LeavePolicyEntity.class, Integer.parseInt(leavepolicyid));
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    Calendar fromcal = Calendar.getInstance();
    fromcal.setTime(sdf.parse(startdate));
    Calendar endCal = Calendar.getInstance();
    endCal.setTime(sdf.parse(endate));
    int actualDays = 0;
    boolean excludeWeekends = lpe.isExcludeweekends();
    int totalDays = 0;
    List daysList = new ArrayList();
    StringBuffer sb = new StringBuffer();
    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE", Locale.US);
    SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MMM-yyyy");

    while (!fromcal.after(endCal)) {
        sb.setLength(0);
        System.out.println("fromcal.get(Calendar.DAY_OF_WEEK)" + fromcal.get(Calendar.DAY_OF_WEEK));
        if (excludeWeekends) {
            if ((7 != fromcal.get(Calendar.DAY_OF_WEEK)) && (1 != fromcal.get(Calendar.DAY_OF_WEEK))) {
                actualDays++;
//                  String asWeek = dateFormat.format(fromcal.getTime());
                sb.append(dateFormat.format(fromcal.getTime()) + "-" + sdf1.format(fromcal.getTime()) + ",true");
            } else {
                sb.append(dateFormat.format(fromcal.getTime()) + "-" + sdf1.format(fromcal.getTime()) + ",false");
            }
        } else {
            sb.append(dateFormat.format(fromcal.getTime()) + "-" + sdf1.format(fromcal.getTime()) + ",true");
            actualDays++;
        }
        daysList.add(sb.toString());
        fromcal.add(Calendar.DATE, 1);
        totalDays++;
    }
//        System.out.println("daysListdaysListdaysList" + daysList);
//        JSONObject json = new JSONObject();
//        json.accumulate("weekdays", daysList);

    response.setContentType("application/json");
    String json = new Gson().toJson(daysList);
    System.out.println("Json" + json);
    response.getWriter().print(json); 
Jquery ajax

 $("[id^='leavetype']").change(function() {
        var startdate = $('#leavetypefromdate').val();
        var enddate = $('#leavetypetodate').val();
//        alert(startdate)
//        alert(enddate)
        if (startdate != "" && enddate != "") {
            if (new Date(startdate) <= new Date(enddate)) {
                $.get("leaverequestvalidation.do?method=validateleavetype", {startdate: startdate, endate: enddate, leavepolicyid: $('#leaveTypeid').val()}, function(responce) {
                    alert(responce);
                    $.each(JSON.parse(responce), function(idx, obj) {
                        alert(1);
                    });

                });
            } else {

                alert("FromDate Cannot Be Greater Than ToDate")
            }
        }
    });
$(“[id^='leavetype']”)。更改(函数(){
var startdate=$('#leavetypefromdate').val();
var enddate=$('#leveTypeToDate').val();
//警报(起始日期)
//警报(结束日期)
如果(开始日期!=“”&结束日期!=“”){

如果(new Date(startdate),如果你只是在这里发布你的JSON对象会有帮助吗?我已经发布了没有ajax调用的所有代码。这样答案就可以从jquery的ajax调用开始,更容易阅读。我已经更新了我的代码。