Problems parsing Spanish characters (á, é, í, ó, ú

2019-08-04 19:07发布

I'm developing a Java app, that calls a PHP from internet that it's giving me a XML response.

In the response is contained this word: "Próximo", but when i parse the nodes of the XML and obtain the response into a String variable, I'm receiving the word like this: "Próximo".

How can i solve this?

3条回答
祖国的老花朵
3楼-- · 2019-08-04 19:49

Probably you are using different encoding in your Java app then encoding of PHP script. Try to set encoding of your stream, for example like that

URL oracle = new URL("http://www.yourpage.com/");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
                        yc.getInputStream(),"utf-8"));//<-- here you set encoding
                                                     //to the same as in your PHP
String inputLine;
while ((inputLine = in.readLine()) != null) 
    System.out.println(inputLine);
查看更多
放我归山
4楼-- · 2019-08-04 19:55

I found solution to this problem... While parsing use "ISO-8859-1" format and use Html.fromHtml(string) method while storing your values into bean .Where "string" is the value inside the each tag of XML response.

查看更多
登录 后发表回答