Unicode Characters appearing as Question Marks in Java JSON Parsing

后端 未结 2 1812
萌比男神i
萌比男神i 2021-01-05 16:35

I have been searching about this for the past few days but I don\'t think I am able to find a correct pointer. Please merge it with the appropriate question if found as dupl

2条回答
  •  无人及你
    2021-01-05 17:25

    You are probably using a default character set that doesn't support the group of special characters. Try using UTF-8 as your charset, something along these lines:

    String str = "{\"alias\": [\"Evr\u00f3pa\", \"\u05d0\u05d9\u05e8\u05d5\u05e4\"]}";
    InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(str.getBytes(Charset.forName("UTF-8"))), Charset.forName("UTF-8"));
    JSONParser parser = new JSONParser(); 
    JSONObject jsonObject = (JSONObject)parser.parse(isr);
    

提交回复
热议问题