简体   繁体   中英

org.json.JSONException: Missing value at character 1

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM