无法识别的标记'title':期待'null','true','false'或NaN

时间:2017-09-25 13:33:35

标签: java jquery json ajax rest

我需要从ajax向java控制器发送请求。标题字段包含一些锚标记。不知道是否会产生问题

我的客户端ajax请求是

url="http://localhost:8080/TS/Add"   

var obj = {
            title : title,
            tagnames : categoryIds,
            documentnames : documents,
            linknames : links,
            createdby : userId
    }
    var post = decodeURIComponent($.param(obj))
$.ajax({
        type : 'POST',
        url : url,
        contentType : 'application/json; charset=utf-8',
        data : post,
        dataType : 'json',
        success : function(data) {
            onComplete();
        }
    });

标题字段包含

title = test <a href="www.google.com" type="0">www.google.com</a>

我的控制器代码是

    @RequestMapping(value = "/Add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<MessageList> addPost(@RequestBody @Valid MessageList messageList, BindingResult bindingResult,
        UriComponentsBuilder ucBuilder) {
//Mycode
}

Modelclass是

public class MessageList extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer id;

public float ratenumber;

public int ratecount;

public String title;    
public String tags;
public String documents;
public String links;

@Transient
private ArrayList<String> tagnames;

@Transient
private ArrayList<String> documentnames;

@Transient
private ArrayList<String> linknames;    


//getters and setters
}

错误是

2017-09-25 09:14:06.518  WARN 9952 --- [nio-8081-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unrecognized token 'title': was expecting 'null', 'true', 'false' or NaN
 at [Source: java.io.PushbackInputStream@370e1ed4; line: 1, column: 10]; nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'titlenew': was expecting 'null', 'true', 'false' or NaN
 at [Source: java.io.PushbackInputStream@370e1ed4; line: 1, column: 10]

0 个答案:

没有答案