3

I am fetching few html content from my server for which I am using JSON parsing. But this converts my html content to unicode values.

For Eg: <p>Spend minimum $10 (in a single same-day receipt) at any outlet<\/p> is getting converted to,

;p&gt;Spend minimum $10 (in a single same-day receipt) at any outlet &lt;/p&gt;

Now if I try to set this to my WebView it displays with HTML tags itself. If I try to encode the data using TextUtils.encode it displays the text with unicode values.

Can anyone help me with this.

How should I fetch a HTML content and display it in WebView?

4 Answers 4

2

I am not getting your question exactly but, If you want to load HTML in web view in you can use

webView.loadDataWithBaseURL(null, html, "text/html", "UTF-8", null);

and if you want to convert &lt and &gt like notation you can use Jsoup Library

Sign up to request clarification or add additional context in comments.

Comments

1

Guys thanks for your help. But I have solved this issue myself. I have elaborated my way of solving the issue.

What I did is,

1)convert the unicode value to Spanned like this,

Spanned ss=Html.fromHtml(;p&gt;Spend minimum $10 (in a single same-day receipt) at any outlet &lt;/p&gt;");

2)Now convert this Spanned to String like this,

String tempString=ss.toString();

3)And now set this to WebView which solved the problem,

  webView.loadData(tempString, "text/html","UTF-8");

Comments

0

Actually this isn't JSON encoder converts data to HTML entities but some other layer, before it passed to JSON encoder.

JSON have nothing to do with HTML tags, usually only quotes encoded by parser (Unicode is supported by most parsers).

You probably need to change the way data is returned by server, to omit encoding of HTML tags braces to HTML entities or decoding entities backin your app.

Update: To decode HTML entities used in HTML tags (and others too) you may use StringEscapeUtils.unescapeHTML()

3 Comments

if it is not the problem, can u suggest me how to display the text in the format what I want.
Thanks for your help ya.. But I have found a simple solution. I have posted here as my answer.
@AndroSelva, np ;). But beware that in [Html.fromHtml](developer.android.com/reference/android/text/… "Not all HTML tags are supported".
0

To show the HTML page inside the Webview why you require the JSON. create web view inside the XML and write below code Inside the Activity you can see the HTML page.

webView = (WebView)findViewById(R.id.webView);
FrameLayout mContentView = (FrameLayout) getWindow().      
getDecorView().findViewById(android.R.id.content);         
final View zoom = this.webView.getZoomControls();        
mContentView.addView(zoom, ZOOM_PARAMS);                   
zoom.setVisibility(View.GONE);
webView.loadUrl("http://www.google.co.in/");

1 Comment

I know this, but the issue was using a unicode string to my webview. Thanks for your help though. I have solved my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.