当前位置: 首页 > 知识库问答 >
问题:

Jacskon解析器:无法识别的标记'tiehe t':应为'null'、'true'或'false'

易宏阔
2023-03-14

我在通过jackson解析器、ajax和jQuery将对象数组传递给controller时遇到了问题。

我的控制器如下所示:

@RequestMapping(value="/saveTimeBooking")
public @ResponseBody ReturnTO saveTimeBooking(@RequestBody TimesheetTO timesheetTO[]) {
    // ...
}
public class TimesheetTO implements Serializable {
    private static final long serialVersionUID = 1L;

    private int activityMasterId;
    private String name;

    private BigDecimal mondayEffort=new BigDecimal(0);
    private BigDecimal tuesdayEffort=new BigDecimal(0);
    private BigDecimal wednesdayEffort=new BigDecimal(0);
    private BigDecimal thursdayEffort=new BigDecimal(0);
    private BigDecimal fridayEffort=new BigDecimal(0);
    private BigDecimal saturdayEffort=new BigDecimal(0);
    private BigDecimal sundayEffort=new BigDecimal(0);
    public int getActivityMasterId() {
        return activityMasterId;
    }
    public String getName() {
        return name;
    }
    public BigDecimal getMondayEffort() {
        return mondayEffort;
    }
    public BigDecimal getTuesdayEffort() {
        return tuesdayEffort;
    }
    public BigDecimal getWednesdayEffort() {
        return wednesdayEffort;
    }
    public BigDecimal getThursdayEffort() {
        return thursdayEffort;
    }
    public BigDecimal getFridayEffort() {
        return fridayEffort;
    }
    public BigDecimal getSaturdayEffort() {
        return saturdayEffort;
    }
    public BigDecimal getSundayEffort() {
        return sundayEffort;
    }
    public void setActivityMasterId(int activityMasterId) {
        this.activityMasterId = activityMasterId;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setMondayEffort(BigDecimal mondayEffort) {
        this.mondayEffort = mondayEffort;
    }
    public void setTuesdayEffort(BigDecimal tuesdayEffort) {
        this.tuesdayEffort = tuesdayEffort;
    }
    public void setWednesdayEffort(BigDecimal wednesdayEffort) {
        this.wednesdayEffort = wednesdayEffort;
    }
    public void setThursdayEffort(BigDecimal thursdayEffort) {
        this.thursdayEffort = thursdayEffort;
    }
    public void setFridayEffort(BigDecimal fridayEffort) {
        this.fridayEffort = fridayEffort;
    }
    public void setSaturdayEffort(BigDecimal saturdayEffort) {
        this.saturdayEffort = saturdayEffort;
    }
    public void setSundayEffort(BigDecimal sundayEffort) {
        this.sundayEffort = sundayEffort;
    }

    public TimesheetTO(){}

    public TimesheetTO( String activityMasterId, 
                        String name, 
                        String mondayEffort,
                        String tuesdayEffort,
                        String wednesdayEffort,
                        String thursdayEffort,
                        String fridayEffort,
                        String saturdayEffort,
                        String sundayEffort)
    {
        this.activityMasterId=Integer.parseInt(activityMasterId);
        this.name=name;
        this.mondayEffort=BigDecimal.valueOf(Double.parseDouble(mondayEffort));
        this.tuesdayEffort=BigDecimal.valueOf(Double.parseDouble(tuesdayEffort));
        this.wednesdayEffort=BigDecimal.valueOf(Double.parseDouble(wednesdayEffort));
        this.thursdayEffort=BigDecimal.valueOf(Double.parseDouble(thursdayEffort));
        this.fridayEffort=BigDecimal.valueOf(Double.parseDouble(fridayEffort));
        this.saturdayEffort=BigDecimal.valueOf(Double.parseDouble(saturdayEffort));
        this.sundayEffort=BigDecimal.valueOf(Double.parseDouble(sundayEffort));
    }
}
var datacounter=0;
/*var totalcount=0;*/
var timesheetTO = new Array();

$("#timeSheetTableId input[id^=activityMasterId]").each(function() {
       $('#activityMasterId_'+datacounter).removeAttr('disabled');
       $('#name_'+datacounter).removeAttr('disabled');

       timesheetTO.push({
           "activityMasterId": $('#activityMasterId_'+datacounter).val(),
           "name": $('#name_'+datacounter).val(),
           "mondayEffort": new Integer($('#mondayEffort_'+datacounter).val()),
           "tuesdayEffort": $('#tuesdayEffort_'+datacounter).val(),
           "wednesdayEffort": $('#wednesdayEffort_'+datacounter).val(),
           "thursdayEffort": $('#thursdayEffort_'+datacounter).val(),
           "fridayEffort": $('#fridayEffort_'+datacounter).val(),
           "saturdayEffort": $('#saturdayEffort_'+datacounter).val(),
           "sundayEffort": $('#sundayEffort_'+datacounter).val()
       });
       datacounter=datacounter+1;
});

var url = contextRoot + "timesheet/saveTimeBooking.htm";
$.ajax({
    type : 'POST',
    url : url,
    async : false,
    timeout : 5000,
    contentType: 'application/json',
    dataType: 'json',
    data : {
        timesheetTO : JSON.stringify(timesheetTO)
    },
    success : function(data, textStatus) {
        alert('successful');

    },
    error : function(xhr, textStatus, errorThrown) {
        alert('request failed in saving timesheet:' + errorThrown + " " + textStatus + " "
                + xhr.toString());
    }
});

以下是json.stringify的结果:

 [{"activityMasterId":"1","name":"Financial Implications","mondayEffort":"0","tuesdayEffort":"0","wednesdayEffort":"0","thur‌​sdayEffort":"0","fridayEffort":"0","saturdayEffort":"0","sundayEffort":"0"},{"act‌​ivityMasterId":"2","name":"Cost estimation","mondayEffort":"0","tuesdayEffort":"0","wednesdayEffort":"0","thursd‌​ayEffort":"0","fridayEffort":"0","saturdayEffort":"0","sundayEffort":"0"}] 

共有1个答案

向杜吟
2023-03-14

问题是您传递的字符串值缺少引号,因此编译器需要一个布尔/空对象

您应该通过调试在运行时验证传递的值,必要时在文本编辑器中复制该值以彻底分析它。

 类似资料: