gpt4 book ai didi

java - Spring MVC 4.2 Jackson解析异常意外字符('%'(代码37))

转载 作者:行者123 更新时间:2023-11-30 03:08:41 25 4
gpt4 key购买 nike

我正在将 Spring 3.1.x 应用程序升级到 Spring 4.2.x。我已经更换了所有 jar ,修复了所有代码/配置问题,现在可以启动应用程序。当向我的 Spring Controller 发布 JSON 请求时,问题就出现了。我收到错误:

org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Unexpected character ('%' (code 37)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')

使用 Chrome 的开发者工具,我可以看到 JSON 请求有效负载实际上是使用 ASCII 字符发送的,第一个字符是“%”符号。但是,ASCII 编码的字符串是有效的 JSON!

Request URL:http://localhost:8080/edge2/app/search/searchResults.ajax
Request Method:POST
Status Code:400 Bad Request
Remote Address:[::1]:8080
Response Headers
Cache-Control:no-cache, no-store, max-age=0, must-revalidate
Connection:close
Content-Language:en
Content-Length:968
Content-Type:text/html;charset=utf-8
Date:Mon, 07 Dec 2015 14:16:09 GMT
Expires:0
Pragma:no-cache
Server:Apache-Coyote/1.1
X-Content-Type-Options:nosniff
X-Frame-Options:DENY
X-XSS-Protection:1; mode=block
Request Headers
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,de;q=0.6
Connection:keep-alive
Content-Length:560
Content-Type:application/json; charset=UTF-8
Cookie:JSESSIONID=A1ED0AC2F3960170E9000FAB1E5FBD45
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/edge2/app/search.htm
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.73 Safari/537.36
X-Requested-With:XMLHttpRequest
Request Payload
%7B%22quoteNumber%22%3A%22%22%2C%22quoteRevision%22%3A%22%22%2C%22createdDateBegin%22%3A%2209%2F07%2F2015%22%2C%22createdDateEnd%22%3A%22%22%2C%22quoteDescription%22%3A%22%22%2C%22productDescription%22%3A%22%22%2C%22productCategory%22%3A%22%22%2C%22customerName%22%3A%22%22%2C%22shipToName%22%3A%22%22%2C%22contactLastName%22%3A%22%22%2C%22soldToNumber%22%3A%22%22%2C%22primarySales%22%3A%22%22%2C%22csrName%22%3A%22%22%2C%22materialNumber%22%3A%22%22%2C%22proposalStatus%22%3A%22REDY%22%2C%22proposalType%22%3A%22%22%2C%22userRole%22%3A%22Administrator%22%7D=

我的 XML 配置中没有对“标准”注释驱动标记进行任何自定义。我的 Controller 方法如下所示:

@RequestMapping(value="/searchResults.ajax", method = RequestMethod.POST)
public @ResponseBody ArrayList<String> showSearchResults(@RequestBody SearchForm searchForm)

我的类路径中有 Jackson 库 (2.6.3)。 Ajax 请求如下所示:

$.ajax({
type: "POST",
contentType : "application/json; charset=utf-8",
url: "../app/search/searchResults.ajax",
data: JSON.stringify(getJSONForm()),
dataType: 'json',
cache: false,
...

getJSONForm 只是创建一个 Javascript 对象并为参数创建名称/值对。

最佳答案

我认为您的问题在于 Json 有效负载,我将您的有效负载放入我得到的 URLDecoder 中:

{"quoteNumber":"","quoteRevision":"","createdDateBegin":"09/07/2015","createdDateEnd":"","quoteDescription":"","productDescription":"","productCategory":"","customerName":"","shipToName":"","contactLastName":"","soldToNumber":"","primarySales":"","csrName":"","materialNumber":"","proposalStatus":"REDY","proposalType":"","userRole":"Administrator"}=

请注意负载末尾的 = 字符。

在此站点中,您可以放置​​有效负载并获取解码后的 Json 字符串。 http://meyerweb.com/eric/tools/dencoder/

我建议您尝试从 RestClient 调用您的服务,例如:

https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo

https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop

关于java - Spring MVC 4.2 Jackson解析异常意外字符('%'(代码37)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34135934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com