我有一个 json 文件,其中包含包含表情符号的字符串
\n{\n "messages": "This is a test -bla-bla test."\n}\nRun Code Online (Sandbox Code Playgroud)\n我的Python代码是:
\nwith open('config.json', 'r') as config_file:\n config = json.load(config_file)\nprint(config["messages"])\nRun Code Online (Sandbox Code Playgroud)\n输出是:
\n\n\n这是一个测试 \xc3\xb0\xc5\xb8\xe2\x80\x9c\xe2\x80\x98-bla-bla 测试。
\n
如何解决这个表情符号编码问题?
\n小智 5
您想要的是确保使用正确的编码保存/读取文件。
with open('config.json', 'r', encoding='utf-8') as config_file:
config = json.load(config_file)
print(config["messages"])
Run Code Online (Sandbox Code Playgroud)