今天遇到一个奇怪的问题, 那就是把txt中的内容读取出来,然后转为json,

txt内容如下:

[{'school':'xijiao','time':1900,'location':'xian','number':10000}]

报错,格式如下:

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2)

python 把字符串转json格式问题

这里是因为这个txt内容中引号为单引号('),但是json需要双引号(")

所以,借助第三方库ast,修正其:

python 把字符串转json格式问题

 

参考:

https://blog.csdn.net/HeatDeath/article/details/79370945

相关文章:

  • 2022-12-23
  • 2022-03-08
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-12-15
  • 2022-12-23
相关资源
相似解决方案