python - 表情符号问题在python中读取json文件
问题描述
我有一个包含表情符号的字符串的 json 文件
{
"messages": "This is a test -bla-bla test."
}
我的python代码是:
with open('config.json', 'r') as config_file:
config = json.load(config_file)
print(config["messages"])
输出是:
这是一个测试ðŸ“'-bla-bla测试。
我该如何解决这个表情符号编码问题?
解决方案
您想要的是确保使用正确的编码保存/读取文件。
with open('config.json', 'r', encoding='utf-8') as config_file:
config = json.load(config_file)
print(config["messages"])
推荐阅读
- python - 如何使用 logoutButton 注销应用程序?
- linux - 德语变音符号未正确存储在 Linux 系统上的 postgres 中
- regex - 如何为多个子目录制定htaccess重写规则
- python - 我该如何做到这一点,以便我的不和谐机器人应要求从 reddit 发送模因?
- c# - ASP.NET Web API 2 通过 Autofac 的依赖注入访问当前用户声明
- django - 如何使用Django在每个请求的基础上在浏览器关闭时设置cookie过期
- mysql - 数据库导入行但行数不等于导出数据库的行
- smartcard - 无法将小程序(.cap 文件)下载到智能卡中:SW 6D 00(无效指令)
- sql - SQL commad 仅从一行复制一列并将其插入另一列
- python - 从两个数组制作一个字典,使第一个数组的值显示第二个数组的索引