简体   繁体   English

com.fasterxml.jackson.core.JsonParseException:无法识别的字符转义符'U'(代码85)

[英]com.fasterxml.jackson.core.JsonParseException: Unrecognized character escape 'U' (code 85)

I've been searching for a solution for hours but without succes. 我一直在寻找解决方案数小时,但没有成功。 I have a json string which I try to map to my java model, but running the code I get the above exception. 我有一个json字符串,尝试映射到我的java模型,但是运行代码时出现上述异常。 JSON String: JSON字符串:

{"productOptions" : {"2-bruch Kreuzfalz" : "nein"},"uploadData" : {"20682967" : {"mergedFile" : "C:\Users\userName\IdeaProjects\projectName\target\test-classes\com\flyeralarm\tools\kronos\order\integration\input\DE151886742X01_20150727131135.pdf"}}}

To save time and space I won't post the java model code but if it'll be needed to solve the task I'd do it. 为了节省时间和空间,我不会发布Java模型代码,但是如果解决任务需要使用它,我会这样做。 I suspect that the error comes because the path to the merged file contains 'C:\\Users' where a backslash is followed by the char 'U'. 我怀疑出现错误是因为合并文件的路径包含“ C:\\ Users”,其中的反斜杠后面是字符“ U”。 Since it is only a suspect I am not quite sure what to do. 由于只是一个嫌疑人,所以我不确定该怎么做。 Am I doing sth. 我在做某事吗? wrong? 错误? How can I solve the error? 我该如何解决错误?

UPDATE 更新

If I am right and jackson tries to escape the 'U' in the path, then why is it so? 如果我是对的,杰克逊试图逃避路径中的“ U”,那为什么会这样呢? I intentionally put the path into the quotes. 我故意把这条路放在引号中。 Why does then jackson considers the slash as an escape attempt? 那么为什么杰克逊将斜线视为逃脱尝试?

The problem is that the original JSON in your question is not valid. 问题是您问题中的原始JSON无效。

According to the JSON specification , the (BNF) syntax for a string is: 根据JSON规范 ,字符串的(BNF)语法为:

string ::= "" 
           " chars "
chars  ::= char
           char chars
char   ::= any-Unicode-character-except-"-or-\-or-control-character
           \"
           \\
           \/
           \b
           \f
           \n
           \r
           \t
           \u four-hex-digits 

In English, that means that a backslash in a string is an escape character, and it CANNOT be followed by a capital U . 用英语来说,这意味着字符串中的反斜杠是转义字符,并且不能在其后跟随大写字母U


If I am right and jackson tries to escape the 'U' in the path, then why is it so? 如果我是对的,杰克逊试图逃避路径中的“ U”,那为什么会这样呢?

Because the JSON specification says that it MUST do that. 因为JSON规范说必须这样做。 The problem is with your understanding of JSON, not in the behaviour of Jackson. 问题在于您对JSON的理解,而不是杰克逊的行为。

If you want to include literal backslashes in a JSON string, you need to escape them ... with backslashes; 如果要在JSON字符串中包含文字反斜杠,则需要使用反斜杠对它们进行转义。 eg 例如

    {"mergedFile" : "C:\\Users\\userName\\frobbit.pdf"}

Just tried to change the backslash into a normal slash and it worked. 只是尝试将反斜杠更改为正常的斜杠就可以了。 Kinda weird that I am forced to use only one type of slashes but at least it works now. Kinda很奇怪,我只能使用一种斜杠,但至少现在可以使用。 To clarify: Changing 澄清一下:

"C:\Users\userName\IdeaProjects\projectName\target\test-classes\com\flyeralarm\tools\kronos\order\integration\input\DE151886742X01_20150727131135.pdf"

into 进入

"C:/Users/a.eirich/IdeaProjects/kronos/src/test/resources/com/flyeralarm/tools/kronos/order/integration/input/DE151886742X01_20150727131135.pdf"

did the job. 做好了

I know this is a bit late, but with 2 backlashes thrown the same error 我知道这有点晚了,但是有2次反冲引发了相同的错误

With 4 backlashes \\\\\\\\ works 有4个反冲\\\\\\\\有效

I have this record in the MySQL database "{\\"mergedFile\\" : \\"C:\\\\\\\\Users\\\\\\\\userName\\\\\\\\frobbit.pdf\\"}" 我在MySQL数据库“ {\\” mergedFile \\“中有此记录:\\” C:\\\\\\\\ Users \\\\\\\\ userName \\\\\\\\\\ frobbit.pdf \\“}”

暂无
暂无

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

相关问题 如何使无法识别的字符转义 &#39;.&#39; (代码 46)被识别 - com.fasterxml.jackson.core.JsonParseException - How to make Unrecognized character escape '.' (code 46) to be Recognized - com.fasterxml.jackson.core.JsonParseException Spring Boot com.fasterxml.jackson.core.JsonParseException:无法识别的令牌 - Spring Boot com.fasterxml.jackson.core.JsonParseException: Unrecognized token 错误 com.fasterxml.jackson.core.JsonParseException:无法识别的令牌 - Error com.fasterxml.jackson.core.JsonParseException: Unrecognized token com.fasterxml.jackson.core.JsonParseException:意外的字符 - com.fasterxml.jackson.core.JsonParseException: Unexpected character Riak&Java - com.fasterxml.jackson.core.JsonParseException:意外的字符(&#39;&lt;&#39;(代码60)) - Riak & Java - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)) com.fasterxml.jackson.core.JsonParseException:意外的字符(&#39;\\&#39;(代码92))[Java] - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('\' (code 92)) [Java] com.fasterxml.jackson.core.JsonParseException:读取json文件时出现意外字符(代码160) - com.fasterxml.jackson.core.JsonParseException: Unexpected character(code 160) while reading the json file RestTemplate::exchange() - com.fasterxml.jackson.core.JsonParseException:意外字符('&lt;'(代码 60)) - RestTemplate::exchange() - com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)) 由以下原因引起的错误:com.fasterxml.jackson.core.JsonParseException:无法识别的令牌“ Employee”:正在期待(“ true”,“ false”或“ null”) - Error Caused by: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Employee': was expecting ('true', 'false' or 'null') com.fasterxml.jackson.core.JsonParseException:无法识别的令牌'Hello':期待(JSON字符串,数字,数组,) - com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Hello': was expecting (JSON String, Number, Array,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM