简体   繁体   English

Java Jackson使用不正确的json字符串解析错误

[英]Java Jackson parsing a error with improper json string

I am trying to parse the following error from FeignException as a Json 我正在尝试将FeignException的以下错误解析为Json

status 412 reading SampleClient#updateUuid(Long,UpdateRequest); content:\n{\"timestamp\":\"2017-06-20T10:46:54.306+0000\",\"status\":412,\"message\":\"Invalid Id\",\"path\":\"/client/12344/updateUuid\",\"error\":true}",

But getting the following error 但是出现以下错误

ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] Servlet.service() for servlet dispatcherServlet threw exception com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'status': was expecting ('true', 'false' or 'null') at [Source: status 412 reading SampleClient#updateUuid(Long,UpdateRequest); 错误org.apache.catalina.core.ContainerBase。[Tomcat]。[localhost]。[/]。[dispatcherServlet] servlet dispatcher的Servlet.service()抛出异常com.fasterxml.jackson.core.JsonParseException:无法识别的令牌状态':在[Source:状态412读取SampleClient#updateUuid(Long,UpdateRequest)时期望(“ true”,“ false”或“ null”); content: {"timestamp":"2017-06-20T10:55:14.380+0000","status":412,"message":"Invalid Id","path":"/client/12344/updateUuid","error":true}; 内容:{“ timestamp”:“ 2017-06-20T10:55:14.380 + 0000”,“ status”:412,“ message”:“ Invalid ID”,“ path”:“ / client / 12344 / updateUuid”,“错误“:真正}; line: 1, column: 7] 行:1,列:7]

I am looking to actually get the "message":"Invalid Id" node. 我正在寻找实际获取“消息”:“无效ID”节点的信息。

Can someone kindly help. 有人可以帮忙吗?

Thanks in advance for you time. 预先感谢您的时间。

You are not sending the parser well formed json. 您没有发送解析器格式正确的json。 You are sending 您正在发送

status 412 reading SampleClient#updateUuid(Long,UpdateRequest); content:\n{\"timestamp\":\"2017-06-20T10:46:54.306+0000\",\"status\":412,\"message\":\"Invalid Id\",\"path\":\"/client/12344/updateUuid\",\"error\":true}",

when you should be sending 您什么时候应该发送

{"timestamp":"2017-06-20T10:46:54.306+0000","status":412,"message":"Invalid Id","path":"/client/12344/updateUuid","error":true}"

Trim the first line (\\n being the line delimiter) and last comma and it should parse, but I have to wonder why you would be doing this in the first place. 修剪第一行(\\ n是行定界符)和最后一个逗号,它应该解析,但是我想知道为什么您会首先这样做。 Please post your code so that we can better comment on your use case. 请发布您的代码,以便我们更好地评论您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM