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

后端 未结 3 470
星月不相逢
星月不相逢 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: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"}
    

提交回复
热议问题