马春杰杰 Exit Reader Mode

json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

读取json文件的时候报错:

Traceback (most recent call last):
  File "testing.py", line 255, in <module>
    main()
  File "/home/sipl/anaconda3/envs/xxx/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 26, in decorate_context
    return func(*args, **kwargs)
  File "testing.py", line 233, in main
    record = json.loads(line[0])
  File "/home/sipl/anaconda3/envs/xxx/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/home/sipl/anaconda3/envs/xxx/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/home/sipl/anaconda3/envs/xxx/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

一开始觉得是双引号的问题,不过检查后确认不是引号的问题,而是格式的问题。

因为我之前把json标注格式化了,重新找到未格式化的文件就好了。

本文最后更新于2022年6月6日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!