"org.json.JSONException: Unterminated string at character" while parsing String to JSONArray

1.3k Views Asked by At

While passing one special use case of String to JSONArray, getting the below error as:

org.json.JSONException: Unterminated string at 25 [character 26 line 1]

My code is as below:

public Object parseResponse(String msg) {
        JSONArray taskVariables = null;
        try {
            if (!StringUtils.isEmpty(msg)) {
                taskVariables = new JSONArray(msg);
            } else {
                taskVariables = createJSONError("Blank or null JSON received.");
            }
        } catch (JSONException e) {
            
        }
      return taskVariables;
}

The input String to the above function is as below:

"[{\"Name\":\"test\\r\\\"}]"

It is parsing till the word "test\r" and the raising the exception while parsing \" which is at the end of the string.

What is the solution for this?

0

There are 0 best solutions below