JsonParseException : 非法的未加引号的字符((CTRL-CHAR,代码 10) [英] JsonParseException : Illegal unquoted character ((CTRL-CHAR, code 10)
问题描述
我正在尝试使用 org.apache.httpcomponents
来使用 Rest API,它将 JSON 格式的数据发布到 API.
I'm trying to use org.apache.httpcomponents
to consume a Rest API, which will post JSON format data to API.
我收到此异常:
引起:com.fasterxml.jackson.core.JsonParseException:非法未加引号的字符((CTRL-CHAR,代码 10)):必须使用转义要包含在字符串中的反斜杠.
Caused by: com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string.
原因是 ctrl-char
包含在 JSON 字符串中.
The reason is because ctrl-char
is included in the JSON string.
有什么办法可以替代这个或其他一些解决方案吗?
Is there any way to replace this or some other solution?
推荐答案
如果 JSON 字符串文字中有换行符(或其他控制字符),就会发生这种情况.
This can happen if you have a newline (or other control character) in a JSON string literal.
{"foo": "bar
baz"}
如果您是生成数据的人,请在创建字符串文字时将实际换行符替换为转义符 "\\n"
.
If you are the one producing the data, replace actual newlines with escaped ones "\\n"
when creating your string literals.
{"foo": "bar\nbaz"}
这篇关于JsonParseException : 非法的未加引号的字符((CTRL-CHAR,代码 10)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!