Android的JSON解析英镑的象征上来的? [英] Android JSON parsing pound symbol coming up as?
问题描述
我有一个包含在它英镑的象征一个JSON文件。这JSON是从暂时存储在手机上的文件拉。它将来自一台服务器,但目前我只是将它存储在手机上。我的JSON文件转换为输入流,并使用的方法将其转换为一个像这样的字符串
I have a JSON file which contains a pound symbol in it. This json is pulled from a file stored on the phone temporarily. It will come from a server, but for time being I am just storing it on the phone. I convert the JSON file to an input stream and use a method to convert it to a string like this
Resources res = getResources();
String sJsonVariables = iStream_to_String(res
.openRawResource(R.raw.widgvariables));
该iStream_to_String方法是这样
The iStream_to_String method is this
public String iStream_to_String(InputStream is) {
BufferedReader rd = new BufferedReader(new InputStreamReader(is), 4096);
String line;
StringBuilder sb = new StringBuilder();
try {
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
} catch (IOException e) {
e.printStackTrace();
}
String contentOfMyInputStream = sb.toString();
return contentOfMyInputStream;
}
我曾尝试打印出使用Log.v来测试它打印出好的JSON的。一切都打印出除英镑的象征罚款。我曾尝试这样的编码它的几种不同的方法
I have tried printing out the json using Log.v to test it is printing out okay. Everything prints out fine except for the pound symbol. I have tried several different ways of encoding it like this
byte []b = sJsonVariables.getBytes();
String s1 = new String(b, "UTF-8");
String s2 = new String(b, "ASCII");
String s3 = new String(b, "Cp1252");
String s4 = new String(b, "ISO8859_1");
但是他们都没有打印出英镑的象征,它要么出来为黑色问号或其他一些奇怪的符号。有谁知道我做错了,我怎么能得到这个符号正确打印出来?
However none of them will print out the pound symbol, it either comes out as a black question mark or some other weird symbol. Does anyone know what I am doing wrong, and how I can get this symbol to print out properly?
推荐答案
与尝试捕捉使用此以及字节[] B = sJsonVariables.getBytes(UTF8);
和字符串S3 =新的String(b的Cp1252);
Use this as well with try catch byte []b = sJsonVariables.getBytes("UTF8");
and the String with String s3 = new String(b, "Cp1252");
这篇关于Android的JSON解析英镑的象征上来的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!