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));
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;
}
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?
Use this as well with try catch
byte []b = sJsonVariables.getBytes("UTF8");and the String withString s3 = new String(b, "Cp1252");