2

I am having an escaped string in a variable and I am trying to make JSON object out of the string. It's throwing the Exception which looks like this : org.json.JSONException: Missing value at character 1 After thorough research, I couldn't find an answer in a stack overflow. But finally, I found a clue and got rid of this problem. I want to share the solution so that others won't waste much of their time in this.

If the string is escaped you need to unescape it before trying to make JSONObject out of it. Below is the sample snippet.

String escapedString = StringEscapeUtils.unescapeJava(escapedString);
JSONObject Json = new JSONObject(escapedString);

I open to hear any other best solutions other than what I mentioned here.

Tejal
  • 764
  • 1
  • 10
  • 39
praneeth
  • 21
  • 1
  • 3

1 Answers1

0

Adding further details about your approach -
Deprecated - org.apache.commons.lang3.StringEscapeUtils
Correct reference - org.apache.commons.lang3.StringEscapeUtils

Haripriya
  • 822
  • 1
  • 14
  • 27