é=é: need to show as it is

2019-08-05 01:09发布

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.

3条回答
The star\"
2楼-- · 2019-08-05 01:31

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.

查看更多
Rolldiameter
3楼-- · 2019-08-05 01:48

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().

查看更多
乱世女痞
4楼-- · 2019-08-05 01:51
登录 后发表回答