JsonParseException:非法的未加引号的字符((CTRL-CHAR,代码10) [英] JsonParseException : Illegal unquoted character ((CTRL-CHAR, code 10)

查看:2899
本文介绍了JsonParseException:非法的未加引号的字符((CTRL-CHAR,代码10)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用org.apache.httpcomponents来使用Rest API,该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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆