我的原始文件夹中有一个名为 school.json 的 json 文件。我想使用以下代码解析该 json 并将其放入 listview 但由于 json 文件中的法语字符,它在我的列表中给了我一些未知字符。那么我该如何修复这个法国角色。
{ "Records" : { "Record" : [
{ "Row" : { "A" : "Collège",
"B" : "8/22/2013",
"C" : "8/23/2013"
} },
{ "Row" : { "A" : "Collège",
"B" : "8/23/2013"
} },
{ "Row" : { "A" : "D'Anjou",
"B" : "8/23/2013"
} },
{ "Row" : { "A" : "Collège",
"B" : "8/26/2013"
} },
{ "Row" : { "A" : "Collège",
"B" : "8/26/2013"
} },
{ "Row" : { "A" : "Collège",
"B" : "8/26/2013"
} },
{ "Row" : { "A" : "School",
"B" : "9/20/2013"
} }
] } }
//-----------------我的方法
public String getJson() {
InputStream is = getResources().openRawResource(R.raw.school);
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader;
try {
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} finally {
try {
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return writer.toString();
}