Volley StringRequest response change the value for apostrophe( ‘ is changed to â)

Viewed 114

The api call sends correct response but when I get the response from Volley StringRequest the Apostrophe sign is changed to unreadable character.

The code I am using for making api call is this:

private fun makeRequest(
    method: Int,
    params: Map<String, String>,
    auth: Boolean,
    token: String = "null",
    logout: Boolean = false
) {
    // Creating a StringRequest
    val req = object : StringRequest(method, url, { res ->
        // Creating JSON object from the response string
        // and passing it to result: (JSONObject) -> Unit function
        result(res.toString().trim())
    }, { volleyError: VolleyError? ->
        // Getting error message and passing it
        // to val error: (String) -> Unit function
        if (!logout) {
            if (!sessionExpire) {
                if (volleyError!!.networkResponse != null) {
                    handleError(volleyError)
                } else {
                    HelperService().displayToast(
                        context!!,
                        context!!.resources.getString(string.internetError)
                    )
                }
            }

        }
        error?.invoke()
    }) {
        // Overriding getParams() to pass our parameters
        override fun getParams(): Map<String, String> {
            if (method == Constants.GET) {
                return super.getParams();
            } else {
                return params
            }
        }

        override fun getHeaders(): MutableMap<String, String> {
            if (auth) {
                val headers = HashMap<String, String>()
                headers["authorization"] = "Token " + token
                return headers;
            } else {
                return super.getHeaders();
            }

        }
    }
    req.retryPolicy = DefaultRetryPolicy(
        60000,
        0,
        DefaultRetryPolicy.DEFAULT_BACKOFF_MULT
    );
    // Adding request to the queue
    volley.add(req)
}

The images for response is attached. First one is response from web, it being displayed normally. The second one is from Android. There are two types of apostrophe used in the name. I need both of them to work. Kindly help.

Update: Replacing works but please recommend a better solution. So, I won't have this type of issue in response.

           val data = res.toString().trim().replace("â\u0080\u0098","'")

Response from web

Response from android

0 Answers
Related