我正在尝试使用json-simple-1.1.1解析JSON
public static void main(String[] args) throws ParseException, IOException{
BufferedReader buff = new BufferedReader(new FileReader("src/qqqqqqqq/json"));
String line = null;
while((line = buff.readLine()) != null){
JSONParser parser = new JSONParser();
Object obj = (Object) parser.parse(line);
JSONObject jsonObj = (JSONObject) obj;
System.out.println((String)jsonObj.get("name"));
}
}我的JSON源文件使用没有BOM的UTF-8
{"name":"ą"}
{"name":"ć"}
{"name":"ń"}
{"name":"ź"}
{"name":"ż"}
{"name":"ó"}println的输出:
Ä…
ć
Ĺ„
Ĺş
ĹĽ
Ăł我做错了什么?
发布于 2015-12-26 23:09:28
FileReader使用默认字符集,该字符集不能是UTF-8。
使用
new BufferedReader(new InputStreamReader(new FileInputStream("src/qqqqqqqq/json"), "UTF-8"));而不是。
https://stackoverflow.com/questions/34472432
复制相似问题