【问题标题】:JSON file gets truncated upon loading into python programJSON文件在加载到python程序时被截断
【发布时间】:2019-09-18 05:15:32
【问题描述】:

我正在尝试将 json 文件加载到我的 python 程序中

with open(filename,'r') as jf:
   datastore = json.load(jf)
print(datastore)```
But this trims about 10% of the JSON file

【问题讨论】:

  • 我认为这会起作用...也许它正在重新排列键而您没有注意到?

标签: python json


【解决方案1】:

不妨试试simplejson.load(infile),看看有什么不同。

文件有多大?

在 Firefox 中打开它,看看是否显示所有内容。

也可以尝试将编码更改为 utf8。

【讨论】:

  • 文件大小为 6MB,是的,当我在 firefox 或任何其他浏览器/编辑器中打开文件时,所有内容都会按原样显示
  • 奇怪.. 你试过 simplejson 吗?这也可能是 python 将 JSON 转换为本机对象的方式。见此链接:stackoverflow.com/questions/17581875/…
猜你喜欢
  • 1970-01-01
  • 2022-10-22
  • 1970-01-01
  • 2021-05-24
  • 1970-01-01
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 2012-12-16
相关资源
最近更新 更多