Replace some special characters with browser code

136 views Asked by At

I am facing a strange situation here.

I am parsing an image link through json and getting the url:

http://developersatwork.com/projects/g4/tools/wp-content/uploads/2015/05/Belbin’s-Team-Roles-100x100.jpg

Whenever I paste this in browser then the image is showing,but whenever I paste it in a notepad then the following url is showing up:

http://developersatwork.com/projects/g4/tools/wp-content/uploads/2015/05/Belbin%E2%80%99s-Team-Roles-100x100.jpg

As you can apostrophe is replaced by %E2%80%99 and Json cannot detect the apostrophe and as a result it is throwing exception:

06-15 14:01:16.955: W/System.err(10146): java.io.FileNotFoundException: http://developersatwork.com/projects/g4/tools/wp-content/uploads/2015/05/Belbin’s-Team-Roles-100x100.jpg

How can I replace such special characters with their corresponding code so that Json can detect them??

I tried UTF-8 encoding and decoding but it is not working.Please give a generalised solution but not for a specific character.

Another one:

http://www.tools4management.dreamhosters.com/wp-content/uploads/2015/06/The-POSITIVE-Model-of-Coaching-–-An-8-step-Outline-to-Motivate-Goal-Accomplishment-100x100.jpg

But when I paste the link from browser to a notepad it shows:

http://www.tools4management.dreamhosters.com/wp-content/uploads/2015/06/The-POSITIVE-Model-of-Coaching-%E2%80%93-An-8-step-Outline-to-Motivate-Goal-Accomplishment-100x100.jpg

SOLUTION

The only workaround was to use a Webview instead of ImageView.

1

There are 1 answers

0
Shivam Verma On

You need to decode the url.

    url = java.net.URLDecoder.decode(url, "UTF-8");