é=é: need to show as it is

淺唱寂寞╮ 提交于 2019-12-11 11:45:17

问题


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



来源:https://stackoverflow.com/questions/16103554/eacute-%c3%a9-need-to-show-as-it-is

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!