gpt4 book ai didi

java - JsonParseException : Illegal unquoted character ((CTRL-CHAR, 代码 10)

转载 作者:IT老高 更新时间:2023-10-28 12:43:34 28 4
gpt4 key购买 nike

我正在尝试使用 org.apache.httpcomponents 来使用 Rest API,它将 JSON 格式的数据发布到 API。

我得到了这个异常(exception):

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 字符串中。

有什么办法可以代替这个或其他解决方案吗?

最佳答案

如果您在 JSON 字符串文字中有换行符(或其他控制字符),就会发生这种情况。

{"foo": "bar
baz"}

如果您是生成数据的人,请在创建字符串文字时将实际的换行符替换为转义的换行符 "\\n"

{"foo": "bar\nbaz"}

关于java - JsonParseException : Illegal unquoted character ((CTRL-CHAR, 代码 10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31537153/

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