JsonParseException : Illegal unquoted character ((CTRL-CHAR, code 10)

后端 未结 3 448
星月不相逢
星月不相逢 2020-12-05 01:52

I\'m trying to use org.apache.httpcomponents to consume a Rest API, which will post JSON format data to API.

I get this exception:

相关标签:
3条回答
  • 2020-12-05 02:12

    On Salesforce platform this error is caused by /, the solution is to escape these as //.

    0 讨论(0)
  • 2020-12-05 02:17

    This can happen if you have a newline (or other control character) in a JSON string literal.

    {"foo": "bar
    baz"}
    

    If you are the one producing the data, replace actual newlines with escaped ones "\\n" when creating your string literals.

    {"foo": "bar\nbaz"}
    
    0 讨论(0)
  • 2020-12-05 02:22

    Using

    mapper.configure(
        JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature(), 
        true
    );
    

    See javadoc:

    /**
     * Feature that determines whether parser will allow
     * JSON Strings to contain unescaped control characters
     * (ASCII characters with value less than 32, including
     * tab and line feed characters) or not.
     * If feature is set false, an exception is thrown if such a
     * character is encountered.
     *<p>
     * Since JSON specification requires quoting for all control characters,
     * this is a non-standard feature, and as such disabled by default.
     */
    

    Old option JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS was deprecated since 2.10.

    Please see also github thread.

    0 讨论(0)
提交回复
热议问题