我正在从存储在应用程序中的 .json 文件中读取 json 响应。这就是我正在做的
private String readJSONResponse(){
InputStream is = getResources().openRawResource(R.raw.json_data);
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
}
catch(Exception e){
}
finally {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return writer.toString();
}
每当我尝试读取文件时,都会以一些数据开头,例如11-11 11:30:57.789: I/System.out(3200): response that has been readed {\rtf1\ansi\ansicpg1252\cocoartf1038\cocoasubrtf360
11-11 11:30:57.789: I/System.out(3200): {\fonttbl\f0\fmodern\fcharset0 Courier;}
11-11 11:30:57.789: I/System.out(3200): {\colortbl;\red255\green255\blue255;}
11-11 11:30:57.789: I/System.out(3200): \margl1440\margr1440\vieww16160\viewh10840\viewkind0
11-11 11:30:57.789: I/System.out(3200): \deftab720
11-11 11:30:57.789: I/System.out(3200): \pard\pardeftab720\ql\qnatural
11-11 11:30:57.799: I/System.out(3200): \f0\fs24 \cf0 \{"status": [\{"response": 13, //this is what is stored in my app
我如何摆脱这些数据和特殊字符,如“\”(请在回复之前检查它。)