I'm trying to parse JSON using json-simple-1.1.1
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"));
}
}
My JSON source file using UTF-8 without BOM
{"name":"ą"}
{"name":"ć"}
{"name":"ń"}
{"name":"ź"}
{"name":"ż"}
{"name":"ó"}
Output from println:
Ä…
ć
Ĺ„
Ĺş
ĹĽ
Ăł
What I am doing wrong?
A FileReader
uses the default charset which must not be UTF-8.
Use
new BufferedReader(new InputStreamReader(new FileInputStream("src/qqqqqqqq/json"), "UTF-8"));
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With