Python Json报错ValueError: Expecting property name: line 1 column 2 (char 1)

Author: Bruce Liu Posted on: 2020-12-05 17:43:21 Visited: 212

使用以下语句报错,通过修改json文件的单引号为双引号解决

#!/usr/bin/python
import json

tfile=open('2.json','r')
jinfo=json.load(tfile)
print(jinfo)

 

执行报错

Traceback (most recent call last):
  File "./gerritreview.py", line 24, in <module>
    jinfo=json.load(tfile)
  File "/usr/lib/python2.7/json/__init__.py", line 290, in load
    **kw)
  File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 2 (char 1)

 

将json文件内容从单引号修改为双引号解决

"{'age':'12','dtest':'13'}"

修改为

{"age":"12","dtest":"13"}
 

 

 

 




Tags:
python ValueError

相关主题:

留言信息:

......期待您的留言!


增加留言、提问或者评论,不用注册,匿名提交,你提交的信息经过审核后才会显示:


© 2008-2022 CunYouLu存有录博客 村友录 存游录 鲁ICP备08005943号