使用以下语句报错,通过修改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
python ValueError