【问题标题】:Python Reading from JSON accented characters coming out wrongPython从JSON重音字符中读取错误
【发布时间】:2018-07-05 01:20:09
【问题描述】:

我的 .JSON 文件中有一个像这样的字符串 ("Theres loads of adventures to be had here;\nYou'll get your own Kobémon\nand get to catch more!"),当我从它读取到 python 文件和 Tkinter 文本框时,我得到 "é" 而不是 é。有没有办法阻止这种情况。我正在使用这个阅读.JSON:(self.Lines = json.load(open("Data/Lines.json")))

【问题讨论】:

  • 你有没有尝试在加载json时添加参数encoding='utf-8'
  • @Idlehands 刚试过;不起作用仍然得到相同的字符

标签: python json decoding diacritics


【解决方案1】:

试试这个:

(self.Lines = json.load(open("Data/Lines.json","rb"), encoding="utf-8"))

不同之处在于以字节为单位加载文件并以utf-8 格式读取它(假设是文件格式)。

【讨论】:

  • 啊!非常感谢。欣赏它。
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 2021-08-02
  • 2013-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-04
相关资源
最近更新 更多