我正在尝试在Textview上显示一个简单的ñ
(特殊西班牙语)字符,而不是ñ
它会显示一些垃圾字符�
。我尝试了很多SOV解决方案,但对我来说并不起作用。ñ
来自SOAP Web服务。
以下是代码:
InputStream in = urlConnection.getInputStream();
SoapObject soapObject=Utility.InToSoapObject(in);
public static SoapObject InToSoapObject(InputStream inputStream) {
SoapObject soap = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER12);
try {
XmlPullParser p = Xml.newPullParser();
p.setInput(inputStream, "utf-8");
envelope.parse(p);
soap = (SoapObject) envelope.bodyIn;
} catch (Exception e) {
e.printStackTrace();
}
return soap;
}
到目前为止,我尝试过很多事情,但对我来说并不适用
用\ u0148
ñ
(Html.fromHtml(STR)
URLEncoder.encode(STR)
将UTF-8替换为iso-8859-1
我正在以正确的方式从SOAP中提取String字符,我已交叉检查。可能是UTF-8
存在一些问题。任何形式的帮助或建议都将受到赞赏。提前致谢
答案 0 :(得分:1)
当我从Web服务中提取String输出时,我遇到了同样的问题但是当我将UTF-8替换为ISO-8859-1时,它得到了解决。我使用的是以下内容,
使用ISO_8859-1格式将InputStream转换为BufferedReader,并处理生成的BufferedReader以转换为String。
private String getResponseString(InputStream stream) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream,"ISO-8859-1"));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
}
finally {
stream.close();
}
return sb.toString();
}
答案 1 :(得分:0)
尝试 -
String = URLEncoder.encode(string, "UTF-8");