【发布时间】:2013-11-11 06:10:43
【问题描述】:
我正在从存储在应用程序中的 .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
之类的一些数据开始
我如何去掉这些数据和特殊字符,如“\”(请在回复前检查。)
【问题讨论】:
-
我认为您已经使用写字板或 Microsoft Word 保存了 json_data 文件。尝试使用记事本保存文件。检查此链接stackoverflow.com/questions/8443860/…
-
@iago 已解决。谢谢你:)