6

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?

Piotr K.
  • 95
  • 1
  • 2
  • 9
  • Possible duplicate of [JSON character encoding](http://stackoverflow.com/questions/3995559/json-character-encoding) – Iamat8 Dec 26 '15 at 14:59

1 Answers1

6

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.

wero
  • 32,544
  • 3
  • 59
  • 84