é=é: need to show as it is

2019-08-05 00:59发布

问题:

I am getting some response from server in text format, it's working fine but in some cases i didn't get string as it is.

Explanation:- My db have one name like cupcaké but when i parse data it's show me cupcaké. I want to show as it is like cupcaké.

I tried URL.Encode and URL.Decode function with the help of utf-8 but none of them helpful. I need universal solution which work for all special character not only for this character.
Here is my jsonparser class, can i need to make changes in this file? or somewhere?

HttpURLConnection conn = null;
    StringBuilder jsonResults = new StringBuilder();
    try {
        URL url = new URL(str);
        conn = (HttpURLConnection) url.openConnection();
        InputStreamReader in = new InputStreamReader(conn.getInputStream());

        // Load the results into a StringBuilder
        int read;
        char[] buff = new char[1024];
        while ((read = in.read(buff)) != -1) {
            jsonResults.append(buff, 0, read);
        }
        json = jsonResults.toString();         
    } catch (MalformedURLException e) {
        Log.e(LOG_TAG, "Error processing Places API URL", e);

How can i show as it is on my screen?
Please give me any reference or hint.

回答1:

After a long search, I found a good answer. These are html entities and can be shown by using the following code:

Html.fromHtml(Html.fromHtml((String) yourstring).toString());  

Now every html entity's converted into the actual string. You can find more details here.



回答2:

You need to work on Sms Encoding Concept . Try some refrence: http://www.codeproject.com/Tips/470755/Encoding-Decoding-7-bit-User-Data-for-SMS-PDU-PDU



回答3:

Note that when you typed cupcaké in your question (before I edited it), the browser displayed it as cupcaké (here it is again, check the answer source: cupcaké). These are "html entities", and you can ask your favorite programming language to decode them into the corresponding character. In php, you'd use html_entity_decode().