Python中的Json编码器期望值错误

2024-04-24 03:46:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个350mb的大Json文件,我想从中提取项目。我使用的代码是:

with open("commitsJson3.json","r", encoding="utf-8-sig") as json_file:
    data = json.load(json_file)


for elem in data['items']:
    for e in elem['commit']:
       if 'message' in e:
           print(elem['commit'][e])

我得到的错误是:

json.decoder.JSONDecodeError错误:期望值:第1行第2180列(char 2179)

我去了具体的栏和行,但我没有看到任何问题。我试图通过一些在线验证器验证我的json,但是它崩溃了,因为它太大了。我可以给你看一些样品,但太大了,希望你能理解。你知道吗


{“total_count”:3,“incomplete_results”:“False”,“items”:c“site_admin”:False},“committer”:{“login”:“acosding”,“id”:1539,“node_id”:“ASJKDHASAD”,“avatar_url”:“https://gits-5.s.fe.se/avatars/u/1329?”目前,美国政府的这一部门已经获得了美国政府部门的id“,,,,“url”网站“{2}”,美国政府的url“{a3}”,追随者的url网站“{a4}”,“以下地区的url“,,,,,,,,,,,,,“url”网站“^{2}”,美国政府的url“^{2}”,html网页网页网址“{a3}”,追随者的url信信信者的url““{a4}”,追随者的url““”,“以下以下地区的url“”,“以下网址”以下,以下,以下,以下的网站网站网站““^{{a5}{a5}{5}{{5}{{{5}{5}{{其他用户{其他用户}{{其他用户},,,,,,,,,“注册网站的url”网站网站网站网址“,,,”,注册网站网站网址““““privacy},“received\u events\u url”:“https://https://gits-5.s.fe.se/api/v3/users/acollden/received_events”,“type”:“用户”


任何帮助都会感激理解Json文件是否有问题,如何验证它,而这样一个大文件等

谢谢你。你知道吗


Tags: 文件用户inhttpsidjsonurlfor
1条回答
网友
1楼 · 发布于 2024-04-24 03:46:27

据我所知,你提供的样品格式不好,如果我尽力的话 仅解码第一部分:

my_json = '{"total_count": 3, "incomplete_results": "False", "items": c "site_admin": False}'

我试着分析它,我得到:

import json

json.loads(my_json, encoding='utf-8-sig')

>>> JSONDecodeError: Expecting value: line 1 column 60 (char 59)

指的是c缺少引号,如果我修复了这个问题:

my_json = '{"total_count": 3, "incomplete_results": "False", "items": "c" "site_admin": False}'
print(json.loads(my_json, encoding='utf-8-sig'))

>>> JSONDecodeError: Expecting ',' delimiter: line 1 column 64 (char 63)

它是指items键之后缺少的,。修复后:

my_json = '{"total_count": 3, "incomplete_results": "False", "items": "c", "site_admin": False}'
print(json.loads(my_json, encoding='utf-8-sig'))

>>> JSONDecodeError: Expecting value: line 1 column 79 (char 78)

指的是最后的False。这可以通过使用false"False"来修复,具体取决于您希望处理的类型。 但是考虑到你的第一个False被当作一个字符串:

my_json = '{"total_count": 3, "incomplete_results": "False", "items": "c", "site_admin": "False"}'
print(json.loads(my_json, encoding='utf-8-sig'))

>>> {'items': 'c', 'total_count': 3, 'site_admin': 'False', 'incomplete_results': 'False'}

最后它成功了

相关问题 更多 >