I am getting a crash on receiving a JSON string from our applications server. We believe that when an entry has "quotes", there are extra escapes added.

In android, how can I determine if I receive such a string , and how do I fix it from the Android side?
Here is our current response string processing:
public String processResponseString(String responseString) {
    if (responseString.startsWith("\"")) {
        responseString = responseString.substring(1, responseString.length());
    }
    if (responseString.endsWith("\"")) {
        responseString = responseString.substring(0, responseString.length() - 1);
    }
    responseString = EscapeUtil.unescapeString(responseString);
    return responseString;
}
Also, logcat does not include the entire json string after the crash, so I cannot see the actual string that is causing the crash.
 java.lang.ClassCastException: com.optiisolutions.housekeeping.model.OptiiAPI.OptiiError cannot be cast to java.util.Map
 at com.optiisolutions.housekeeping.network.OptiiHTTPClientRetroFit$2.success(OptiiHTTPClientRetroFit.java:186)
 at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
optiiClient.postRequest(event.getRequest(), new Callback<Map<String, Object>>() {
    @Override
     public void success(Map<String, Object> stringObjectMap, Response response) {
         Log.d(TAG, "Successful response: " + stringObjectMap.toString());
          String result = (String) stringObjectMap.get(OPTII_RESULT_TYPE);
          String json = gson.toJson(stringObjectMap, Map.class);
I think you need to parse Map in to JSON Like below code  by using JSONValue.
optiiClient.postRequest(event.getRequest(), new Callback<Map<String, Object>>() {
    @Override
     public void success(Map<String, Object> stringObjectMap, Response response) {
         Log.d(TAG, "Successful response: " + stringObjectMap.toString());
        // For JsonValue you need to add one jar file .
         String json= JSONValue.toJSONString(stringObjectMap);
         Log.d(TAG, "Successful json: " + json);
}
need to add jar javax.json-1.0.2.jar in gradle  dependencies 
dependencies {
    compile files('libs/javax.json-1.0.2.jar')
}
Download javax.json-1.0.2.jar Download from below link:
http://www.java2s.com/Code/Jar/j/Downloadjavaxjson102jar.htm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With