Cannot deserialize instance of string from VALUE_STRING value at [line:1, column:167]

I am trying to send a REST request containing JSON data in Java, and as a response, I am getting the following error:
Method failed: HTTP/1.1 400 Bad Request
[ {
"message" : "Cannot deserialize instance of string from VALUE_STRING value at [line:1, column:167]",
"errorCode" : "JSON_PARSER_ERROR"
} ]

Apparently JSON has problems with parsing the data. However, what seems strange is that when I took a look at other errors of this type on the Internet, they all contained the offending value, e.g.
Cannot deserialize instance of datetime from VALUE_STRING value 2011-09-27T23:01:01Z at ...

In my case there is nothing between "value" and "at", but there is a double space which suggests the value that was supposed to be parsed is empty.
graham on 18-01-2013 10:03
It turned out the offending character in the string was a new line character. The was I solved it is that I used the JSONObject.escape method to escape the JSON string before putting it into the request:
String json = JSONObject.escape(json);
graham on 18-01-2013 10:05

Post an answer

Do you have a solution to this problem, or want to comment on it? Other users will appreciate your help!
Your answer or comment:
Show formatting hints
HTML is disallowed, but in your text you can use the following markup
  • [code][/code] for a block of code
  • [tt][/tt] for inline code
  • [link]link href|link anchor[/link] for links
  • [b][/b] for bold text
+ Ask a question
If you have a technical question related to programming and computers, ask it here. Other users will help you solve it!
Unanswered questions
Share your knowledge by helping others solve their problems