这是我的JSON文件的内容
cat ./myfile.json
{u'Records': [{u'eventVersion': u'2.0', }]}
如何读取此JSON文件?
我尝试使用以下代码读取文件,
def Read_json_file(jsonFile):
jsonDy = {}
if os.path.exists(jsonFile):
with open(jsonFile, 'rt') as fin:
jsonDy = json.load(fin)
else:
print("JSON file not available ->",
jsonFile)
sys.exit(1)
print("jsonDy -> ", jsonDy)
但是出现以下错误,
Traceback (most recent call last):
File "a.py", line 125, in
Main()
File "a.py", line 18, in Main
content = Read_json_file(eventFile)
File "a.py", line 44, in Read_json_file
jsonDy = json.load(fin)
File "/usr/lib64/python2.7/json/__init__.py", line 290, in load
**kw)
File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 2 (char 1)
我的理解是, u'代表unicode表示法,但不确定如何读取此文件
PS :我正在使用Python 2.7