Is There A Htmldecode?
I am downloading a JSONObject from a web site. The entries are however HTML-encoded, using " and & tags. Is there an easy way to get these to Java strings? S
Solution 1:
OK, I simply went to write my own quick fix. Not efficient, but that's OK for the purpose. A 5-minutes-solution.
publicstaticString unescape (String s)
{
while (true)
{
int n=s.indexOf("&#");
if (n<0) break;
int m=s.indexOf(";",n+2);
if (m<0) break;
try
{
s=s.substring(0,n)+(char)(Integer.parseInt(s.substring(n+2,m)))+
s.substring(m+1);
}
catch (Exception e)
{
return s;
}
}
s=s.replace(""","\"");
s=s.replace("<","<");
s=s.replace(">",">");
s=s.replace("&","&");
return s;
}
Solution 2:
I've heard of success in using the Apache Commons on Android.
You should be able to use StringEscapeUtils.unescapeHtml()
(from the Lang package).
Here are the (fairly straightforward) directions on using the Apache Commons libraries in your Android apps: Importing org.apache.commons into android applications.
Post a Comment for "Is There A Htmldecode?"