com.fasterxml.jackson.core。JsonParseException:未识别字符escape 'U'(代码85)

时间:2020-12-25 17:08:53

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 String:

我一直在寻找解决办法,但没有成功。我有一个json字符串,我试着映射到我的java模型,但是运行代码我得到了上述异常。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. 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'. 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?

为了节省时间和空间,我不会发布java模型代码,但如果需要它来解决我所做的任务。我怀疑这个错误是由于合并文件的路径包含了“C:\用户”,后面是一个反斜杠,后面是char 'U'。因为这只是个嫌疑犯,我不太确定该怎么办。我做错了吗?我怎样才能解决这个错误呢?

UPDATE

更新

If I am right and jackson tries to escape the 'U' in the path, then why is it so? I intentionally put the path into the quotes. Why does then jackson considers the slash as an escape attempt?

如果我是对的,而杰克逊试图逃离“你”的道路,那为什么会这样?我故意把这条路放进引号里。为什么杰克逊认为斜线是逃跑的企图?

2 个解决方案

#1


2  

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?

如果我是对的,而杰克逊试图逃离“你”的道路,那为什么会这样?

Because the JSON specification says that it MUST do that. The problem is with your understanding of JSON, not in the behaviour of Jackson.

因为JSON规范说它必须这样做。问题在于您对JSON的理解,而不是Jackson的行为。

If you want to include literal backslashes in a JSON string, you need to escape them ... with backslashes; e.g.

如果您想要在JSON字符串中包含文本的反斜杠,您需要摆脱它们……反斜线;如。

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

#2


0  

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. 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.

做这份工作。

#1


2  

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?

如果我是对的,而杰克逊试图逃离“你”的道路,那为什么会这样?

Because the JSON specification says that it MUST do that. The problem is with your understanding of JSON, not in the behaviour of Jackson.

因为JSON规范说它必须这样做。问题在于您对JSON的理解,而不是Jackson的行为。

If you want to include literal backslashes in a JSON string, you need to escape them ... with backslashes; e.g.

如果您想要在JSON字符串中包含文本的反斜杠,您需要摆脱它们……反斜线;如。

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

#2


0  

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. 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.

做这份工作。