Unicode Characters appearing as Question Marks in Java JSON Parsing

后端 未结 2 1791
萌比男神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:04

    The problem isn't with your JSON, it's with your System.out.println(). Those characters can't be represented in the character encoding either of your terminal (or your IDE, if that is where you ran it) or of the encoding being used by System.out in your environment.

    Files can not contain Unicode characters. Files are streams of bytes, but Unicode characters are multiple bytes (usually two) in size. This is where character encodings become relevant. Unicode characters must be converted to a sequence of bytes to write them to a file (including System.out). One of the most commonly used encodings for Unicode characters is UTF-8. The trick for software programmers is to always use the correct character encoding when converting between bytes and characters. Lacking the correct encoding in a single place, for example in a debug println() call, will give erroneous and misleading output.

提交回复
热议问题