Passing in JSON array to spring MVC Controller

前端 未结 3 672
悲&欢浪女
悲&欢浪女 2020-12-22 10:22

I am trying to pass a JSON array into spring MVC Controller like such:

 var myList = new Array(); 
data._children.forEach( function (d) { 
                           


        
相关标签:
3条回答
  • 2020-12-22 10:37

    You can try

    @RequestParam("myList") myList tempmyList


    @Param myList tempmyList

    in addition, class names must begin with a capital letter.

    0 讨论(0)
  • 2020-12-22 10:47

    Even I was facing same problem. My client request was right and generated proper json file. but still i was getting same error.

    I solved this error using @JsonIgnoreProperties(ignoreUnknown = true) in pojo class.

    refer this link. Spring MVC : The request sent by the client was syntactically incorrect

    0 讨论(0)
  • 2020-12-22 10:48

    try to add this to you ajax call it should fix the unsupported response :

    headers : {
        'Accept' : 'application/json',
        'Content-Type' : 'application/json'
    },
    

    this is a full example of ajax call that is working for me :

    $.ajax({
                dataType : "json",
                url : this.baseurl + "/dataList",
                headers : {
                    'Accept' : 'application/json',
                    'Content-Type' : 'application/json'
                },
                data : JSON.stringify(params),
                type : 'POST',
                success : function(data) {
                    self.displayResults(data);
                },
                error : function(jqXHR,textStatus,errorThrown ){
                    showPopupError('Error','error : ' + textStatus, 'ok');
                }
            });
    
    0 讨论(0)
提交回复
热议问题