返回时JSON响应被篡改

时间:2014-02-01 13:39:45

标签: jquery json spring-mvc spring-3

我正在使用JQuery和Spring MVC进行AJAX调用。

客户端脚本:

$.ajax({
    type : "POST",
    url : "channelIntentionDetails.html",
    data : stringifiedSearchParameter,
    beforeSend : function(
            xhr) {

        xhr
                .setRequestHeader(
                        "Content-Type",
                        "application/json");
    },
    success : function(
            response) {

        alert("IntentionDetails : "
                + response.results);
        if (jQuery
                .isEmptyObject(response)) {
            alert("No data found for");
        }
        drawIntentionPieChart(response.results);
    }
});

控制器方法:

@RequestMapping(value = "channelIntentionDetails.html", method = RequestMethod.POST)
  public @ResponseBody
  com.lnt.sapphire.pojo.Report getChannelIntentionDetails(@RequestBody SearchParameters searchParameters) {

    System.out.println("In ReportController.getChannelIntentionDetails(...), searchParameters " + searchParameters);

    com.lnt.sapphire.pojo.Report report = channelDetailsService.getIntentionDetails(searchParameters);

    System.out.println("Returning from ReportController.getChannelIntentionDetails(...), report " + report);

    return report;
  }

报告POJO:

public class Report {

    private Map<String, Collection<String>> parameterWiseResult;
    private Collection<String> results;
    private String result;


    public Map<String, Collection<String>> getParameterWiseResult() {
        return this.parameterWiseResult;
    }

    public Collection<String> getResults() {
        return this.results;
    }

    public void setParameterWiseResult(
            final Map<String, Collection<String>> parameterWiseResult) {
        this.parameterWiseResult = parameterWiseResult;
    }

    public void setResults(final Collection<String> result) {
        this.results = result;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "Report [parameterWiseResult=" + parameterWiseResult
                + ", results=" + results + ", result=" + result + "]";
    }

}

服务器控制台上的输出(结果是数组):

Returning from ReportController.getChannelIntentionDetails(...), report Report [parameterWiseResult=null, results=[{ "_id" : { "SpId" : 664 , "Intention_category" : "" , "Report_Id" : 2 , "Channel_Id" : 1} , "count" : 10}], result=null]

但我在脚本中得到的回复(检查alert.results的警告):

{ "_id" : { "SpId" : 664 , "Intention_category" : "" , "Report_Id" : 2 , "Channel_Id" : 1} , "count" : 10}

现在这会导致解析问题 - 数组[]消失了!

任何提示?

1 个答案:

答案 0 :(得分:-1)

尝试

var reponsedata = JSON.parse(response);  alert(“IntentionDetails:”+ responsedata.results);